Add search option to apply term boosting #274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Term boosting (giving greater or lower importance to specific query terms) was previously not supported. It was technically possible by using the
boostDocument
search option (as shown here: #268) but cumbersome and error prone.This commit adds a new search option,
boostTerm
, which makes it a lot easier to apply term boosting. The option is a function that is invoked with each query term (as normalized byprocessTerm
), as well as the term index in the query, and the array of all query terms, and is expected to return a numeric boost factor.A factor greater than 1 increases the importance of a term for the relevance scoring, a factor less than 1 decreases the importance of a term, and a factor equal to 1 is neutral.
Examples
Boosting specific terms:
Boosting the first few terms in the query: