You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Karthik N S <ka...@controlnet.co.in> on 2004/12/13 11:11:13 UTC
RE: HITCOLLECTOR+SCORE+DELIMMA
Hi
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
Karthik
-----Original Message-----
From: Vikas Gupta [mailto:vgupta@cs.utexas.edu]
Sent: Monday, December 13, 2004 3:17 PM
To: Lucene Users List
Subject: RE: HITCOLLECTOR+SCORE+DELIMA
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org