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 Document boost, is it working?
Date Tue, 30 Oct 2007 20:26:04 GMT
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());

}

}

 
 
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message