Skip to content

Conversation

lucaong
Copy link
Owner

@lucaong lucaong commented Jul 19, 2024

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 by processTerm), 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:

const boostFactors = {
  'motorcycle': 1.2,
  'foo': 0.7
}

miniSearch.search('Motorcycle Maintenance', {
  boostTerm: (term) => boostFactors[term] || 1
})

Boosting the first few terms in the query:

const boostFactors = [1.5, 1.2]

miniSearch.search('Motorcycle Maintenance', {
  boostTerm: (term, i) => boostFactors[i] || 1
})

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 search term, and is expected to return a numeric boost factor.
@lucaong lucaong merged commit ec9c0ff into master Jul 22, 2024
2 checks passed
@lucaong lucaong deleted the term-boosting branch July 22, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant