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