0
votes

I have some fields that are ordered in the index (e.g. lexographical Strings). I'd like to give a higher boost/score to the higher values.

What is the preferred way to do this in Lucene 4? (obtaining the exact value through a hit to the IndexCache is suboptimal)

(There are plently of Google hits for earlier versions of Lucene, but the API has changed substantially with great improvements to the indexing system.)

1
I assume simply sorting on the field's value would not be adequate? Also, is it acceptable to use field-level (that is, index time) boosting for this?femtoRgon
I'm currently using index time boosting (but, for various reasons, this only works because we re-index regularly... e.g. to boost "recent" documents). I don't know what you mean by "sorting on the field's value". If there were a way to use the natural index order of the fields, that would be perfect: avoiding actually looking at the document is critical (as with any efficient Lucene query).fommil
I've noted a dramatic slow-down in insertion speed when doing the index boosting. In Lucene 4, index-time boosting means looping through all the indexable fields and manually boosting them.fommil

1 Answers

1
votes

You can sort on a fields value lexicographically by passing a Sort into your call to IndexSearcher.search.

SortField primarySort = new SortField("field", SortField.Type.STRING);
Sort sort = new Sort(primarySort, SortField.FIELD_SCORE);
searcher.search(query, hits, sort);

That will sort, first, on the lexicographic ordering of the given field, then by relevance score. You can add as many sort fields as you like when constructing your Sort.