Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

querying without hits

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


dmassart at acm

Oct 13, 2008, 11:44 PM

Post #1 of 5 (5140 views)
Permalink
querying without hits

Dear all,
Could one of you point me to an example of code for querying without using
the deprecated class Hits ?

Thank you,

David


emailgane at yahoo

Oct 14, 2008, 1:50 AM

Post #2 of 5 (5024 views)
Permalink
Re: querying without hits [In reply to]

Hello David,

Use TopDocs or TopFieldDocs to collect only required hits.

----
TopDocs topDocs = searcher.search(query,10)
int docID = topDocs.scoreDocs[index].doc;
Document doc = searcher.doc(docID);
----

Regards
Ganesh


----- Original Message -----
From: "David Massart" <dmassart [at] acm>
To: <java-user [at] lucene>
Sent: Tuesday, October 14, 2008 12:14 PM
Subject: querying without hits


> Dear all,
> Could one of you point me to an example of code for querying without using
> the deprecated class Hits ?
>
> Thank you,
>
> David
>

Send instant messages to your online friends http://in.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


hossman_lucene at fucit

Oct 14, 2008, 8:16 PM

Post #3 of 5 (5013 views)
Permalink
Re: querying without hits [In reply to]

: Could one of you point me to an example of code for querying without using
: the deprecated class Hits ?

The demo code included with Lucene releases was updated in Lucene 2.4 so
that it does not use the Hits class.

-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


dmassart at acm

Oct 15, 2008, 2:33 AM

Post #4 of 5 (5006 views)
Permalink
Re: querying without hits [In reply to]

Thanks guys.
Just looking at the examples and I wonder if there is a means to directly
get the total number of hits. Or is it always necessary to search for a few
top docs, get the the total number of hits and then create a new collector
to get all the results?

TopDocCollector collector = new TopDocCollector(5);

searcher.search(query, collector);

int numTotalHits = collector.getTotalHits();

collector = new TopDocCollector(numTotalHits);

searcher.search(query, collector);

ScoreDoc[] hits = collector.topDocs().scoreDocs;

If the later is true, is the code above the best way to do this?

Cheers,

David

On Wed, Oct 15, 2008 at 5:16 AM, Chris Hostetter
<hossman_lucene [at] fucit>wrote:

>
> : Could one of you point me to an example of code for querying without
> using
> : the deprecated class Hits ?
>
> The demo code included with Lucene releases was updated in Lucene 2.4 so
> that it does not use the Hits class.
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>
>


lucene at mikemccandless

Oct 15, 2008, 2:47 AM

Post #5 of 5 (5012 views)
Permalink
Re: querying without hits [In reply to]

If you want to keep every single hit, which is very dangerous for a
large index, you should make a new collector.

Here's an example (pulled from upcoming LIA revision):

public class AllDocCollector extends HitCollector {
List<ScoreDoc> docs = new ArrayList<ScoreDoc>();
public void collect(int doc, float score) {
if (score > 0.0f) {
docs.add(new ScoreDoc(doc, score));
}
}

public void reset() {
docs.clear();
}

public List<ScoreDoc> getHits() {
return docs;
}
}

If you need the results sorted then you should do the sort at the end.

Mike

David Massart wrote:

> Thanks guys.
> Just looking at the examples and I wonder if there is a means to
> directly
> get the total number of hits. Or is it always necessary to search
> for a few
> top docs, get the the total number of hits and then create a new
> collector
> to get all the results?
>
> TopDocCollector collector = new TopDocCollector(5);
>
> searcher.search(query, collector);
>
> int numTotalHits = collector.getTotalHits();
>
> collector = new TopDocCollector(numTotalHits);
>
> searcher.search(query, collector);
>
> ScoreDoc[] hits = collector.topDocs().scoreDocs;
>
> If the later is true, is the code above the best way to do this?
>
> Cheers,
>
> David
>
> On Wed, Oct 15, 2008 at 5:16 AM, Chris Hostetter
> <hossman_lucene [at] fucit>wrote:
>
>>
>> : Could one of you point me to an example of code for querying
>> without
>> using
>> : the deprecated class Hits ?
>>
>> The demo code included with Lucene releases was updated in Lucene
>> 2.4 so
>> that it does not use the Hits class.
>>
>> -Hoss
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
>> For additional commands, e-mail: java-user-help [at] lucene
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.