Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 94265 invoked from network); 30 Oct 2007 21:42:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Oct 2007 21:42:18 -0000 Received: (qmail 28256 invoked by uid 500); 30 Oct 2007 21:41:40 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 27972 invoked by uid 500); 30 Oct 2007 21:41:40 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 27961 invoked by uid 99); 30 Oct 2007 21:41:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2007 14:41:40 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.112.118.2] (HELO bromine.sosstaffing.com) (216.112.118.2) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2007 21:41:43 +0000 Received: from [10.49.220.35] (l038-22321.hcwan.net [10.49.220.35]) by bromine.sosstaffing.com (Postfix) with ESMTP id 30CA74DCF37 for ; Tue, 30 Oct 2007 15:41:22 -0600 (MDT) Message-ID: <4727A4BE.8090105@thebluezone.net> Date: Tue, 30 Oct 2007 15:40:14 -0600 From: John Griffin User-Agent: Thunderbird 1.5.0.13 (X11/20070809) MIME-Version: 1.0 To: java-user@lucene.apache.org Subject: Re: Document boost, is it working? References: <001501c81b33$1887e3a0$0a00a8c0@BRUNO> In-Reply-To: <001501c81b33$1887e3a0$0a00a8c0@BRUNO> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Bruno Dery wrote: > Hi all the following is using Lucene 2.2.0. > > I've been trying to alter the scoring of my search results to boost by > date. My idea was to boost documents while indexing using the date but > it doesn't work. So I put together this little sample piece of code to > investigate further and apparently setting the document boost does > nothing. In my example below, you'd expect the display the output 20 2 > and 10 but I get 1 1 1. Is this normal behavior and if so how am I > supposed to use document boosting because it seems like I'm missing > something... > > Here's the sample of code: > > ----------- > > > import org.apache.lucene.analysis.standard.StandardAnalyzer; > > import org.apache.lucene.document.Document; > > import org.apache.lucene.document.Field; > > import org.apache.lucene.index.IndexReader; > > import org.apache.lucene.index.IndexWriter; > > import org.apache.lucene.store.FSDirectory; > > public class IndexTest { > > /** > > * @param args > > */ > > public static void main(String[] args) throws Exception { > > // Create bogus index > > IndexWriter writer = new > IndexWriter(FSDirectory.getDirectory("C:/lucene_test/"), new > StandardAnalyzer(), true); > > writer.setUseCompoundFile(true); > > Document doc = new Document(); > > doc.add(new Field("testfield", "high ranking", Field.Store.YES, > Field.Index.TOKENIZED)); > > doc.setBoost(20); > > writer.addDocument(doc); > > doc = new Document(); > > doc.add(new Field("testfield", "low ranking", Field.Store.YES, > Field.Index.TOKENIZED)); > > doc.setBoost(2); > > writer.addDocument(doc); > > doc = new Document(); > > doc.add(new Field("testfield", "mid ranking", Field.Store.YES, > Field.Index.TOKENIZED)); > > doc.setBoost(10); > > writer.addDocument(doc); > > writer.close(); > > // Read bogus index > > IndexReader reader = > IndexReader.open(FSDirectory.getDirectory("C:/lucene_test/")); > > System.out.println(reader.document(0).getBoost()); > > System.out.println(reader.document(1).getBoost()); > > System.out.println(reader.document(2).getBoost()); > > } > > } > > > > > > Bruno, After your comment // read bogus index, replace your code with this. IndexSearcher searcher = new IndexSearcher("/home/griffij/lucene_test/"); final QueryParser parser = new QueryParser("testfield", new StandardAnalyzer()); final Query query = parser.parse("ranking"); Hits hits = searcher.search(query); for (int x = 0; x < hits.length(); x++) { System.out.println(hits.doc(x) + "score=> " + hits.score(x)); } You'll see that the boost does indeed take effect. The boost value isn't stored with the document you set it against. It takes effect during the scoring process and effects all fields in the document. John G. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org