Skip to content

Commit

Permalink
Tuning bm25, adding sort order
Browse files Browse the repository at this point in the history
Modify suggestion mode flow
  • Loading branch information
maneeshpm committed Feb 14, 2021
1 parent 1077e3e commit e1734e5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ Search::iterator Search::begin() const {
Xapian::Query query;
try {
query = queryParser->parse_query(this->query, flags, prefix);

// In suggestion mode, parsing the query with OP_PHRASE provides
// better results.Combined with the subquery above provides single
// term and phrase compatibility.
if(suggestion_mode){
queryParser->set_default_op(Xapian::Query::op::OP_PHRASE);
query = Xapian::Query(Xapian::Query::OP_OR, queryParser->parse_query(this->query), query);
}
} catch (Xapian::QueryParserError& e) {
estimated_matches_number = 0;
return nullptr;
Expand All @@ -379,6 +387,16 @@ Search::iterator Search::begin() const {
}
}

// In suggestion mode, we are searching over a separate title index.
// Default BM25 is not adapted for this case, tuning down wdf factor
// (k1) and increasing length normalization factor(b) is necessary.
// The document set is first sorted by their relevance score then by
// value so that suggestion results are closer to search string.
if (suggestion_mode) {
enquire.set_weighting_scheme(Xapian::BM25Weight(0.001,0,1,1,0.5));
enquire.set_sort_by_relevance_then_value(valuesmap["title"], true);
}

enquire.set_query(query);

#if WITH_LEV
Expand Down

0 comments on commit e1734e5

Please sign in to comment.