Fuzziness to 0.1 by default, 0.2 if zero result
This commit is contained in:
@@ -70,15 +70,17 @@ export async function initSearchEngineFromData(json: string): Promise<void> {
|
|||||||
/**
|
/**
|
||||||
* Searches the index for the given query,
|
* Searches the index for the given query,
|
||||||
* and returns an array of raw results
|
* and returns an array of raw results
|
||||||
* @param query
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
async function search(query: Query): Promise<SearchResult[]> {
|
async function search(
|
||||||
|
query: Query,
|
||||||
|
options = { fuzzy: 0.1 }
|
||||||
|
): Promise<SearchResult[]> {
|
||||||
if (!query.segmentsToStr()) return []
|
if (!query.segmentsToStr()) return []
|
||||||
|
|
||||||
let results = minisearchInstance.search(query.segmentsToStr(), {
|
let results = minisearchInstance.search(query.segmentsToStr(), {
|
||||||
prefix: true,
|
prefix: true,
|
||||||
fuzzy: term => (term.length > 4 ? 0.2 : false),
|
// fuzzy: term => (term.length > 4 ? 0.2 : false),
|
||||||
|
fuzzy: options.fuzzy,
|
||||||
combineWith: 'AND',
|
combineWith: 'AND',
|
||||||
boost: {
|
boost: {
|
||||||
basename: settings.weightBasename,
|
basename: settings.weightBasename,
|
||||||
@@ -158,6 +160,9 @@ export async function getSuggestions(
|
|||||||
): Promise<ResultNote[]> {
|
): Promise<ResultNote[]> {
|
||||||
// Get the raw results
|
// Get the raw results
|
||||||
let results = await search(query)
|
let results = await search(query)
|
||||||
|
if (results.length == 0) {
|
||||||
|
results = await search(query, { fuzzy: 0.2 })
|
||||||
|
}
|
||||||
if (!results.length) return []
|
if (!results.length) return []
|
||||||
|
|
||||||
// Extract tags from the query
|
// Extract tags from the query
|
||||||
|
|||||||
Reference in New Issue
Block a user