lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Performance for search when I need all Hits
Date Wed, 11 Feb 2004 09:53:09 GMT
On Feb 11, 2004, at 2:36 AM, Anand Stephen wrote:
> I am trying to convert the using Hits to HitCollector. Does anyone 
> have any
> examples?
> This is what am trying to do, how do I get the score?
>
> <code>
>         Searcher searcher = new IndexSearcher(indexDir);
>         IndexReader indexReader = IndexReader.open(indexDir);
>         final BitSet bits = new BitSet(indexReader.maxDoc());
>         searcher.search(lquery, new HitCollector() {
>             public void collect(int doc, float score) {
>                 bits.set(doc);
>             }
>         });

You should "collect" the score within your HitCollector too.  The idea 
of using a HitCollector is because you want access to all the documents 
returned, so I suggest you set up a data structure that collects all 
the documents and their score within the collect() method rather than 
setting bits.

You could simply combine the code you have below into the collect() 
method to extract the pieces you want there.

	Erik


>
>         int size = bits.length();
>
>         String[] values = new String[size];
>         String type = null;
>         ArrayList results = new ArrayList(size);
>
>         for (int i = 0,j = size; i < j; i++) {
>             final Document document = searcher.doc(i);
>             type = document.get("TYPE");
>             //hits.doc(i).get("TYPE");
>             values[i] = document.get("ID");
> //            System.out.println("score = " + score);
> // how do i get the score???
> //            resultsMap.put(hits.doc(i).get("ID"), new Float(score));
>
>         }


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


Mime
View raw message