lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Griffin <jgrif...@thebluezone.net>
Subject Re: Document boost, is it working?
Date Tue, 30 Oct 2007 21:13:14 GMT
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,

Use Luke to examine your simple index and see if the boost is 
registering. It will be on Luks's documents page about in the middle of 
the screen. That'll at least tell you if it's registering with the 
documents.

John G.


---------------------------------------------------------------------
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