How to rank custom search results?

My lucene index contains documents with the field "itemName". This field is activated with a gain from 0 to 1. When I create BooleanQuery, I would like the results to be evaluated by matching offers and boostfactor, so the formula looks like this:

score = (count_of_matching_clauses / count_of_total_clauses + boost_factor) / 2

The score will always be a float between 0 and 1. 1 in case all offers coincide, and the boost coefficient is 1.

For example, if the value of the "itemName" field is for three documents without a gain:

document1: "java is an island"
document2: "the secret of monkey island"
document3: "java island adventures"

and BooleanQuery will look like this:

TermQuery query1 = new TermQuery(new Term("name","java"));
TermQuery query2 = new TermQuery(new Term("name","island"));

BooleanQuery query = new BooleanQuery();
query.add(query1, BooleanClause.Occur.SHOULD);
query.add(query2, BooleanClause.Occur.SHOULD);

than document1, it will be received with an estimate of (2/2 +0) / 2 = 0.5, because: count_of_matching_clauses = 2 and count_of_total_clauses = 2

document2 (1/2 + 0)/2 = 0,25, : count_of_matching_clauses = 1 count_of_total_clauses = 2

3, (2/2 +0)/2 = 0,5, : count_of_matching_clauses = 2 count_of_total_clauses = 2

lucene? lucene ?

+3
1

, Similarity . Javadoc ( ) . . , , Searcher.explain()

BTW, , , - . , 0,5 0,25.

EDIT: , Lucene v2.4, v5.3.1.

+1

Source: https://habr.com/ru/post/1712982/


All Articles