Merge of Insiders features tied to 'Aji Panca' funding goal

This commit is contained in:
squidfunk
2022-02-17 17:20:36 +01:00
parent 90137011e9
commit b5e71dfcb1
57 changed files with 1670 additions and 13500 deletions

View File

@@ -55,6 +55,7 @@ export interface SearchIndexDocument {
location: string /* Document location */
title: string /* Document title */
text: string /* Document text */
tags?: string[] /* Document tags */
}
/* ------------------------------------------------------------------------- */
@@ -202,6 +203,7 @@ export class Search {
/* Set up fields */
this.field("title", { boost: 1e3 })
this.field("text")
this.field("tags", { boost: 1e6 })
/* Index documents */
for (const doc of docs)
@@ -243,7 +245,7 @@ export class Search {
.reduce<SearchResultItem>((item, { ref, score, matchData }) => {
const document = this.documents.get(ref)
if (typeof document !== "undefined") {
const { location, title, text, parent } = document
const { location, title, text, tags, parent } = document
/* Compute and analyze search query terms */
const terms = getSearchQueryTerms(
@@ -257,6 +259,7 @@ export class Search {
location,
title: highlight(title),
text: highlight(text),
...tags && { tags: tags.map(highlight) },
score: score * (1 + boost),
terms
})

View File

@@ -61,9 +61,10 @@ export function setupSearchDocumentMap(
for (const doc of docs) {
const [path, hash] = doc.location.split("#")
/* Extract location and title */
/* Extract location, title and tags */
const location = doc.location
const title = doc.title
const tags = doc.tags
/* Escape and cleanup text */
const text = escapeHTML(doc.text)
@@ -97,7 +98,8 @@ export function setupSearchDocumentMap(
documents.set(location, {
location,
title,
text
text,
...tags && { tags }
})
}
}