Lucene setboost doesn't work
- by Keven
Hi all,
OUr team just upgrade lucene from 2.3 to 3.0 and we are confused about the setboost and getboost of document. What we want is just set a boost for each document when add them into index, then when search it the documents in the response should have different order according to the boost I set. But it seems the order is not changed at all, even the boost of each document in the search response is still 1.0. Could some one give me some hit? Following is our code:
String[] a = new String[] { "schindler", "spielberg", "shawshank", "solace", "sorcerer", "stone", "soap",
"salesman", "save" };
List strings = Arrays.asList(a);
AutoCompleteIndex index = new Index();
IndexWriter writer = new IndexWriter(index.getDirectory(), AnalyzerFactory.createAnalyzer("en_US"), true,
MaxFieldLength.LIMITED);
float i = 1f;
for (String string : strings) {
Document doc = new Document();
Field f = new Field(AutoCompleteIndexFactory.QUERYTEXTFIELD, string, Field.Store.YES,
Field.Index.NOT_ANALYZED);
doc.setBoost(i);
doc.add(f);
writer.addDocument(doc);
i += 2f;
}
writer.close();
IndexReader reader2 = IndexReader.open(index.getDirectory());
for (int j = 0; j < reader2.maxDoc(); j++) {
if (reader2.isDeleted(j)) {
continue;
}
Document doc = reader2.document(j);
Field f = doc.getField(AutoCompleteIndexFactory.QUERYTEXTFIELD);
System.out.println(f.stringValue() + ":" + f.getBoost() + ", docBoost:" + doc.getBoost());
doc.setBoost(j);
}