Setting for fuzziness
This commit is contained in:
@@ -188,12 +188,26 @@ export class Omnisearch {
|
|||||||
|
|
||||||
logDebug('Starting search for', query)
|
logDebug('Starting search for', query)
|
||||||
|
|
||||||
|
let fuzziness: number
|
||||||
|
switch (settings.fuzziness) {
|
||||||
|
case '0':
|
||||||
|
fuzziness = 0
|
||||||
|
break
|
||||||
|
case '1':
|
||||||
|
fuzziness = 0.1
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
fuzziness = 0.2
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
let results = this.minisearch.search(query.segmentsToStr(), {
|
let results = this.minisearch.search(query.segmentsToStr(), {
|
||||||
prefix: term => term.length >= options.prefixLength,
|
prefix: term => term.length >= options.prefixLength,
|
||||||
// length <= 3: no fuzziness
|
// length <= 3: no fuzziness
|
||||||
// length <= 5: fuzziness of 10%
|
// length <= 5: fuzziness of 10%
|
||||||
// length > 5: fuzziness of 20%
|
// length > 5: fuzziness of 20%
|
||||||
fuzzy: term => (term.length <= 3 ? 0 : term.length <= 5 ? 0.1 : 0.2),
|
fuzzy: term =>
|
||||||
|
term.length <= 3 ? 0 : term.length <= 5 ? fuzziness / 2 : fuzziness,
|
||||||
combineWith: 'AND',
|
combineWith: 'AND',
|
||||||
boost: {
|
boost: {
|
||||||
basename: settings.weightBasename,
|
basename: settings.weightBasename,
|
||||||
@@ -216,7 +230,6 @@ export class Omnisearch {
|
|||||||
ext.startsWith(e.startsWith('.') ? e : '.' + e)
|
ext.startsWith(e.startsWith('.') ? e : '.' + e)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
console.log(query.query.ext, results.length)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter query results that match the path
|
// Filter query results that match the path
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ import {
|
|||||||
} from 'obsidian'
|
} from 'obsidian'
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import { database } from './database'
|
import { database } from './database'
|
||||||
import { K_DISABLE_OMNISEARCH, getTextExtractor, isCacheEnabled } from './globals'
|
import {
|
||||||
|
K_DISABLE_OMNISEARCH,
|
||||||
|
getTextExtractor,
|
||||||
|
isCacheEnabled,
|
||||||
|
} from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
|
|
||||||
interface WeightingSettings {
|
interface WeightingSettings {
|
||||||
@@ -49,6 +53,7 @@ export interface OmnisearchSettings extends WeightingSettings {
|
|||||||
splitCamelCase: boolean
|
splitCamelCase: boolean
|
||||||
openInNewPane: boolean
|
openInNewPane: boolean
|
||||||
verboseLogging: boolean
|
verboseLogging: boolean
|
||||||
|
fuzziness: '0' | '1' | '2'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,6 +264,29 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Fuzziness
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Fuzziness')
|
||||||
|
.setDesc(
|
||||||
|
"Define the level of fuzziness for the search. The higher the fuzziness, the more results you'll get."
|
||||||
|
)
|
||||||
|
.addDropdown(dropdown =>
|
||||||
|
dropdown
|
||||||
|
.addOptions({
|
||||||
|
0: 'Exact match',
|
||||||
|
1: 'Not too fuzzy',
|
||||||
|
2: 'Fuzzy enough',
|
||||||
|
})
|
||||||
|
.setValue(settings.fuzziness)
|
||||||
|
.onChange(async v => {
|
||||||
|
if (!['0', '1', '2'].includes(v)) {
|
||||||
|
v = '2'
|
||||||
|
}
|
||||||
|
settings.fuzziness = v as '0' | '1' | '2'
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
//#endregion Behavior
|
//#endregion Behavior
|
||||||
|
|
||||||
//#region User Interface
|
//#region User Interface
|
||||||
@@ -467,6 +495,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
|||||||
highlight: true,
|
highlight: true,
|
||||||
showPreviousQueryResults: true,
|
showPreviousQueryResults: true,
|
||||||
simpleSearch: false,
|
simpleSearch: false,
|
||||||
|
fuzziness: '0',
|
||||||
|
|
||||||
weightBasename: 3,
|
weightBasename: 3,
|
||||||
weightDirectory: 2,
|
weightDirectory: 2,
|
||||||
@@ -491,4 +520,4 @@ export async function saveSettings(plugin: Plugin): Promise<void> {
|
|||||||
|
|
||||||
export function isPluginDisabled(): boolean {
|
export function isPluginDisabled(): boolean {
|
||||||
return app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1'
|
return app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user