Fixed search boost not being applied to document sections

This commit is contained in:
squidfunk 2022-10-19 23:25:46 +07:00
parent f13a5526d0
commit 922fde0701
2 changed files with 6 additions and 4 deletions

View File

@ -45,11 +45,11 @@ class SearchIndex(BaseIndex):
def add_entry_from_context(self, page): def add_entry_from_context(self, page):
index = len(self._entries) index = len(self._entries)
super().add_entry_from_context(page) super().add_entry_from_context(page)
entry = self._entries[index]
# Add document tags, if any # Add document tags, if any
if page.meta.get("tags"): if page.meta.get("tags"):
if type(page.meta["tags"]) is list: if type(page.meta["tags"]) is list:
entry = self._entries[index]
entry["tags"] = [ entry["tags"] = [
str(tag) for tag in page.meta["tags"] str(tag) for tag in page.meta["tags"]
] ]
@ -64,6 +64,7 @@ class SearchIndex(BaseIndex):
if "search" in page.meta: if "search" in page.meta:
search = page.meta["search"] search = page.meta["search"]
if "boost" in search: if "boost" in search:
for entry in self._entries[index:]:
entry["boost"] = search["boost"] entry["boost"] = search["boost"]
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------

View File

@ -45,11 +45,11 @@ class SearchIndex(BaseIndex):
def add_entry_from_context(self, page): def add_entry_from_context(self, page):
index = len(self._entries) index = len(self._entries)
super().add_entry_from_context(page) super().add_entry_from_context(page)
entry = self._entries[index]
# Add document tags, if any # Add document tags, if any
if page.meta.get("tags"): if page.meta.get("tags"):
if type(page.meta["tags"]) is list: if type(page.meta["tags"]) is list:
entry = self._entries[index]
entry["tags"] = [ entry["tags"] = [
str(tag) for tag in page.meta["tags"] str(tag) for tag in page.meta["tags"]
] ]
@ -64,6 +64,7 @@ class SearchIndex(BaseIndex):
if "search" in page.meta: if "search" in page.meta:
search = page.meta["search"] search = page.meta["search"]
if "boost" in search: if "boost" in search:
for entry in self._entries[index:]:
entry["boost"] = search["boost"] entry["boost"] = search["boost"]
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------