lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno Dery" <bruno.d...@evidencematters.com>
Subject RE: Document boost, is it working?
Date Tue, 30 Oct 2007 21:48:21 GMT
Thanks for the help, you're right your example works. However looking in
Luke I also see only ones (1 1 1) as the document boost. 

I imagine Luke use's Lucene's Document.getBoost() function. Shouldn't
this be considered a bug, as I'd expect to retrieve the same boost
number (or at least some factor of it) when I look at my documents once
indexed? Or perhaps there is something I'm not understanding about this
Document.getBoost function, normally you expect a getter to return you
the exact value you entered with the setter.


-----Original Message-----
From: John Griffin [mailto:jgriffin@thebluezone.net] 
Sent: Tuesday, October 30, 2007 5:40 PM
To: java-user@lucene.apache.org
Subject: Re: Document boost, is it working?


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



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


Mime
View raw message