Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 66564 invoked from network); 13 Dec 2004 09:47:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 Dec 2004 09:47:31 -0000 Received: (qmail 94307 invoked by uid 500); 13 Dec 2004 09:47:09 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 94268 invoked by uid 500); 13 Dec 2004 09:47:08 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 94242 invoked by uid 99); 13 Dec 2004 09:47:07 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=LINES_OF_YELLING,SUBJ_ALL_CAPS X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: 128.83.139.10 is neither permitted nor denied by domain of vgupta@cs.utexas.edu) Received: from mail.cs.utexas.edu (HELO mail.cs.utexas.edu) (128.83.139.10) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 13 Dec 2004 01:47:00 -0800 Received: from bifrost.cs.utexas.edu (vgupta@bifrost.cs.utexas.edu [128.83.130.9]) by mail.cs.utexas.edu (8.13.1/8.13.1) with ESMTP id iBD9ksat017528 for ; Mon, 13 Dec 2004 03:46:55 -0600 (CST) Received: (from vgupta@localhost) by bifrost.cs.utexas.edu (8.12.11/8.12.11/Submit) id iBD9ks0O028145; Mon, 13 Dec 2004 03:46:54 -0600 Date: Mon, 13 Dec 2004 03:46:54 -0600 (CST) From: Vikas Gupta To: Lucene Users List Subject: RE: HITCOLLECTOR+SCORE+DELIMA In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N > 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