fommil
fommil

Reputation: 5875

Boost based on indexed field

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

Upvotes: 0

Views: 77

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

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.

Upvotes: 1

Related Questions