lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <yo...@lucidimagination.com>
Subject Re: Hits and TopDoc
Date Tue, 20 Oct 2009 21:43:19 GMT
Hmm, yes, I should have thought of quoting the havadoc :-)
The Hits javadoc has been udpated though... we shouldn't be pushing
people toward collectors unless they really need them:

 *   TopDocs topDocs = searcher.search(query, numHits);
 *   ScoreDoc[] hits = topDocs.scoreDocs;
 *   for (int i = 0; i < hits.length; i++) {
 *     int docId = hits[i].doc;
 *     Document d = searcher.doc(docId);
 *     // do something with current hit


-Yonik
http://www.lucidimagination.com



On Tue, Oct 20, 2009 at 5:27 PM, Steven A Rowe <sarowe@syr.edu> wrote:
> Hi Nathan,
>
> On 10/20/2009 at 5:03 PM, Nathan Howard wrote:
>> This is sort of related to the above question, but I'm trying to update
>> some (now depricated) Java/Lucene code that I've become aware of once we
>> started using 2.4.1 (we were previously using 2.3.2):
>>
>> Hits results = MultiSearcher.search(Query));
>>
>> int start = currentPage * resultsPerPage;
>> int stop = (currentPage + 1) * resultsPerPage();
>>
>> for(int x = start; (x < searchResults.length()) && (x < stop); x++)
>> {
>>     Document doc = searchResults.doc(x);
>>     // do search post-processing with the Document
>> }
>>
>> Results per page is normally small (10ish or so).
>>
>> I'm having difficulty figuring out how to get TopDocs to replicate this
>> paging functionality (which the application must maintain).
>
> From <http://lucene.apache.org/java/2_4_1/api/core/org/apache/lucene/search/Hits.html>:
> =====
> Deprecated. Hits will be removed in Lucene 3.0.
>
> Instead e. g. TopDocCollector and TopDocs can be used:
>
>   TopDocCollector collector = new TopDocCollector(hitsPerPage);
>   searcher.search(query, collector);
>   ScoreDoc[] hits = collector.topDocs().scoreDocs;
>   for (int i = 0; i < hits.length; i++) {
>     int docId = hits[i].doc;
>     Document d = searcher.doc(docId);
>     // do something with current hit
>     ...
> =====
>
> Construct the TopDocCollector with your "stop" variable instead of "hitsPerPage", initialize
the loop control variable with the value of your "start" variable instead of 0, and you should
be good to go.
>
> Steve
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message