fix: tweak search

This commit is contained in:
taskylizard
2023-12-21 14:15:21 +00:00
parent 1ab86fa03a
commit 0ca6c65c0d
4 changed files with 168 additions and 120 deletions

View File

@@ -78,7 +78,24 @@ export default defineConfig({
themeConfig: {
search: {
options: {
miniSearch: { searchOptions: { combineWith: "AND" } },
miniSearch: {
searchOptions: {
combineWith: "AND",
fuzzy: false,
// @ts-ignore
boostDocument: (_, term, storedFields: Record<string, string | string[]>) => {
const titles = (storedFields?.titles as string[])
.filter((t) => !!t)
.map((t) => t.toLowerCase());
// Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
const titleIndex =
titles.map((t, i) => (t?.includes(term) ? i : -1)).find((i) => i >= 0) ?? -1;
if (titleIndex >= 0) return 10000 - titleIndex;
return 1;
},
},
},
detailedView: true,
},
provider: "local",