lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vikas Gupta <vgu...@cs.utexas.edu>
Subject RE: HITCOLLECTOR+SCORE+DELIMA
Date Mon, 13 Dec 2004 09:46:54 GMT
> On Dec 10, 2004, at 7:39 AM, Karthik N S wrote:
> > I am still in delima on How to use the HitCollector for returning
> > Hits hits
> > between scores  0.2f to 1.0f ,
> >
> > There is not a simple example for the same, yet lot's of talk on usage
> > for
> > the same on the form.

1) I am not 100% sure about this but it might work.

Add the code starting with >>>>> in IndexSearcher.java::search()

 // inherit javadoc
  public TopDocs search(Query query, Filter filter, final int nDocs)
       throws IOException {
    Scorer scorer = query.weight(this).scorer(reader);
    if (scorer == null)
      return new TopDocs(0, new ScoreDoc[0]);

    final BitSet bits = filter != null ? filter.bits(reader) : null;
    final HitQueue hq = new HitQueue(nDocs);
    final int[] totalHits = new int[1];
    scorer.score(new HitCollector() {
	public final void collect(int doc, float score) {
	  if (score > 0.0f &&			  // ignore zeroed buckets
>>>>>         && score >0.2f && score<1.0f)
	      (bits==null || bits.get(doc))) {	  // skip docs not in bits
	    totalHits[0]++;
            hq.insert(new ScoreDoc(doc, score));
	  }
	}
      });



2) Filter examples are in Lucene in Action book, Chapter 5. I wrote an
example as well:



        String query = "odyssey";

        BooleanQuery bq = new BooleanQuery();
        bq.add(new TermQuery(new Term("content", query)), true, false);

        BooleanQuery bqf = new BooleanQuery();
        bqf.add(new TermQuery(new Term("H2", query)), true, false);

        Filter f = new QueryFilter(bqf);

        IndexReader reader = IndexReader.open(new File(dir, "index").getCanonicalPath());
        Searcher luceneSearcher = new org.apache.lucene.search.IndexSearcher(reader);
        luceneSearcher.setSimilarity(new NutchSimilarity());

	//Logically the following would be executed as follows: Find all
        //the docs matching bq. Select the ones which matchbqf
        hits = luceneSearcher.search(bq, f);

        System.out.print("query: " + query);

        System.out.println("Total hits: " + hits.length());

3) delima is spelled as dilemma


-Vikas Gupta

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


Mime
View raw message