add aliases support to plex search

This commit is contained in:
Amir Pourmand 2025-09-04 18:53:02 +03:30
parent 0a57d032a7
commit 8de40437a1
2 changed files with 13 additions and 2 deletions

View File

@ -9,6 +9,8 @@ interface Item {
title: string title: string
content: string content: string
tags: string[] tags: string[]
aliases: string[]
[key: string]: any
} }
// Can be expanded with things like "term" in the future // Can be expanded with things like "term" in the future
@ -35,6 +37,10 @@ let index = new FlexSearch.Document<Item>({
field: "tags", field: "tags",
tokenize: "forward", tokenize: "forward",
}, },
{
field: "aliases",
tokenize: "forward",
},
], ],
}, },
}) })
@ -271,6 +277,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""), title: searchType === "tags" ? data[slug].title : highlight(term, data[slug].title ?? ""),
content: highlight(term, data[slug].content ?? "", true), content: highlight(term, data[slug].content ?? "", true),
tags: highlightTags(term.substring(1), data[slug].tags), tags: highlightTags(term.substring(1), data[slug].tags),
aliases: data[slug].aliases ?? [],
} }
} }
@ -409,7 +416,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
query: query, query: query,
// return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch) // return at least 10000 documents, so it is enough to filter them by tag (implemented in flexsearch)
limit: Math.max(numSearchResults, 10000), limit: Math.max(numSearchResults, 10000),
index: ["title", "content"], index: ["title", "content", "aliases"],
tag: tag, tag: tag,
}) })
for (let searchResult of searchResults) { for (let searchResult of searchResults) {
@ -430,7 +437,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
searchResults = await index.searchAsync({ searchResults = await index.searchAsync({
query: currentSearchTerm, query: currentSearchTerm,
limit: numSearchResults, limit: numSearchResults,
index: ["title", "content"], index: ["title", "content", "aliases"],
}) })
} }
@ -442,6 +449,7 @@ async function setupSearch(searchElement: Element, currentSlug: FullSlug, data:
// order titles ahead of content // order titles ahead of content
const allIds: Set<number> = new Set([ const allIds: Set<number> = new Set([
...getByField("title"), ...getByField("title"),
...getByField("aliases"),
...getByField("content"), ...getByField("content"),
...getByField("tags"), ...getByField("tags"),
]) ])
@ -478,6 +486,7 @@ async function fillDocument(data: ContentIndex) {
title: fileData.title, title: fileData.title,
content: fileData.content, content: fileData.content,
tags: fileData.tags, tags: fileData.tags,
aliases: fileData.aliases,
}), }),
) )
} }

View File

@ -16,6 +16,7 @@ export type ContentDetails = {
links: SimpleSlug[] links: SimpleSlug[]
tags: string[] tags: string[]
content: string content: string
aliases: string[]
richContent?: string richContent?: string
date?: Date date?: Date
description?: string description?: string
@ -110,6 +111,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
links: file.data.links ?? [], links: file.data.links ?? [],
tags: file.data.frontmatter?.tags ?? [], tags: file.data.frontmatter?.tags ?? [],
content: file.data.text ?? "", content: file.data.text ?? "",
aliases: file.data.frontmatter?.aliases ?? [],
richContent: opts?.rssFullHtml richContent: opts?.rssFullHtml
? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true })) ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
: undefined, : undefined,