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

Allow adjusting search boost for title and tags fields #4512

Closed
4 tasks done
ekoleda-codaio opened this issue Oct 18, 2022 · 8 comments
Closed
4 tasks done

Allow adjusting search boost for title and tags fields #4512

ekoleda-codaio opened this issue Oct 18, 2022 · 8 comments
Labels
change request Issue requests a new feature or improvement resolved Issue is resolved, yet unreleased if open

Comments

@ekoleda-codaio
Copy link

Contribution guidelines

I want to suggest an idea and checked that ...

  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... the documentation does not mention anything about my idea
  • ... there are no open or closed issues that are related to my idea

Description

Allow developers to adjust the search boost that comes from a search term matching the title or tags of a page. Currently these are hardcoded at 1e3 and 1e6 respectively.

/* Set up fields */
this.field("title", { boost: 1e3 })
this.field("text")
this.field("tags", { boost: 1e6, extractor: doc => {
const { tags = [] } = doc as SearchDocument
return tags.reduce((list, tag) => [
...list,
...lunr.tokenizer(tag)
], [] as lunr.Token[])
} })

Use Cases

You can tune search results with search boosting, and the page recommends starting with low values. However if you are trying to boost a page above another that has an exact match in the title, your boost must be greater than 1e3, which is quite huge. Allowing developer to adjust these constants would make it easier to tune search.

Screenshots / Mockups

Add entries somewhere in mkdocs.yml, perhaps under theme.

@squidfunk
Copy link
Owner

Thanks for suggesting. Additional to boosts, there are some other parameters that we can expose to tune search, which is an excellent addition to the built-in search plugin. I'll cook something up in the coming weeks.

@squidfunk squidfunk added the change request Issue requests a new feature or improvement label Oct 19, 2022
@squidfunk
Copy link
Owner

I'll be revisiting this feature request shortly, as soon as beta 9 reaches a stable status and is released 😊 The reason why this takes some time is that the search was refactored and that first needs to be merged back into Insiders, so efforts are not duplicated. I'm sorry for the inconvenience, but it'll be worth the wait, as I'm planning other new interesting features for search that are made possible by the refactoring, including the things that were asked in this issue.

@ekoleda-codaio
Copy link
Author

Thanks for the update. I found a weighting that counteracts these built in boosts well enough for now, so this isn't urgent.

@squidfunk
Copy link
Owner

bde0f4f63 adds support for customizable field boosts. I still need to update the documentation, but this is now possible:

plugins:
  - search:
      fields:
        title:
          boost: 0.5 # Current default: 1e3
        tags:
          boost: 2.0 # Current default: 1e6

Note that values currently need to be floats, so 2 will not work, but 2.0 will. This is the beginning of the next iteration on the search plugin, which will bring powerful customization possibilities, so the implementation is still work in progress.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jan 8, 2023
@ekoleda-codaio
Copy link
Author

Exciting, thanks! Anyway you could automatically cast the numbers to floats? I feel like that's something I'll forget when using this feature.

@squidfunk
Copy link
Owner

Absolutely agree, but I'm still fighting MkDocs config validation format 😅 Haven't found a way yet to use a union (int | float), but wanted your feedback nonetheless.

@squidfunk
Copy link
Owner

Fixed in 1999599 – you can now use integers or floats. This feature has been part of Insiders for some time now, but it's still inofficial, because it is only the beginning of field-level configuration. We won't add documentation at this point. You can use this feature as described in #4512 (comment). Later this year, search will get new functionality.

@squidfunk
Copy link
Owner

Released as part of 9.0.13+insiders-4.31.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change request Issue requests a new feature or improvement resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants