From 9f35531cd974bef1dd77be3011109b55560ec499 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 23 Oct 2022 09:37:51 +0200 Subject: [PATCH] Fuzziness to 0.1 by default, 0.2 if zero result --- src/search/search.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/search/search.ts b/src/search/search.ts index b399011..98eda29 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -70,15 +70,17 @@ export async function initSearchEngineFromData(json: string): Promise { /** * Searches the index for the given query, * and returns an array of raw results - * @param query - * @returns */ -async function search(query: Query): Promise { +async function search( + query: Query, + options = { fuzzy: 0.1 } +): Promise { if (!query.segmentsToStr()) return [] let results = minisearchInstance.search(query.segmentsToStr(), { prefix: true, - fuzzy: term => (term.length > 4 ? 0.2 : false), + // fuzzy: term => (term.length > 4 ? 0.2 : false), + fuzzy: options.fuzzy, combineWith: 'AND', boost: { basename: settings.weightBasename, @@ -158,6 +160,9 @@ export async function getSuggestions( ): Promise { // Get the raw results let results = await search(query) + if (results.length == 0) { + results = await search(query, { fuzzy: 0.2 }) + } if (!results.length) return [] // Extract tags from the query @@ -246,4 +251,4 @@ export function removeFromMinisearch(document: IndexedDocument): void { minisearchInstance.remove(document) } -// #endregion \ No newline at end of file +// #endregion