lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karthik N S" <>
Date Mon, 13 Dec 2004 10:11:13 GMT

Vikas Gupta

Since Erik Replied to me on my last mail, A FILTER cand be built for the
same can be to
fetch scrores between  0.2f to 1.0f.

Can u please spare me some code for the same.

[ Sorry for the Spell mistake, My Mail IDE does not have one ]
With regards

-----Original Message-----
From: Vikas Gupta []
Sent: Monday, December 13, 2004 3:17 PM
To: Lucene Users List

> 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

 // 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
            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 = File(dir,
        Searcher luceneSearcher = new;
        luceneSearcher.setSimilarity(new NutchSimilarity());

	//Logically the following would be executed as follows: Find all
        //the docs matching bq. Select the ones which matchbqf
        hits =, 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:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message