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

Search boosting does not affect sections #4511

Closed
5 tasks done
ekoleda-codaio opened this issue Oct 18, 2022 · 3 comments
Closed
5 tasks done

Search boosting does not affect sections #4511

ekoleda-codaio opened this issue Oct 18, 2022 · 3 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@ekoleda-codaio
Copy link

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Search boosting is not being applied to section entries on the page.

Expected behaviour

When a boost is applies to a page, all content on the page receives the boost.

Actual behaviour

Only the entry for entire page receives the boost. Entries for the individual sections of the page don't receive the boost.

Steps to reproduce

  1. Add search boosting to a page that has multiple sections (h2 headers).
  2. Build the doc.
  3. Look at search_index.json.

Only the entry corresponding to the entire page will have the boost. The entries corresponding to sections of the page will not.

Looking at the code, the boost is only applied to a single entry, but the search plugin generates multiple ones. A solution may involve searching over all of the entries for ones that point to the same page, and applying the boost to all of them.

def add_entry_from_context(self, page):
index = len(self._entries)
super().add_entry_from_context(page)
entry = self._entries[index]
# Add document tags, if any
if page.meta.get("tags"):
if type(page.meta["tags"]) is list:
entry["tags"] = [
str(tag) for tag in page.meta["tags"]
]
else:
log.warning(
"Skipping 'tags' due to invalid syntax [%s]: %s",
page.file.src_uri,
page.meta["tags"]
)
# Add document boost for search
if "search" in page.meta:
search = page.meta["search"]
if "boost" in search:
entry["boost"] = search["boost"]

Package versions

  • Python: 3.10.7
  • MkDocs: 1.3.1
  • Material: 8.5.2

Configuration

N/A

System information

N/A

@squidfunk squidfunk added the bug Issue reports a bug label Oct 19, 2022
@squidfunk
Copy link
Owner

Thanks for reporting – that's unintended.

@squidfunk
Copy link
Owner

Fixed in 922fde0. Boosts are now applied to all sections of a document. This still needs to be merged into Insiders, which will take a little more time given the difference search implementation. I'll follow up shortly.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Oct 19, 2022
@squidfunk
Copy link
Owner

Released as part of 8.5.7. Insiders did not exhibit this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants