Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search option to apply term boosting #274

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Add search option to apply term boosting #274

merged 1 commit into from
Jul 22, 2024

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