diff --git a/src/notes.ts b/src/notes.ts index 6713730..957cdbf 100644 --- a/src/notes.ts +++ b/src/notes.ts @@ -22,16 +22,19 @@ export function resetNotesCache(): void { } export async function loadNotesCache(): Promise { - if (settings.storeIndexInFile && await app.vault.adapter.exists(notesCacheFilePath)) { + if ( + settings.storeIndexInFile && + (await app.vault.adapter.exists(notesCacheFilePath)) + ) { try { const json = await app.vault.adapter.read(notesCacheFilePath) notesCache = JSON.parse(json) console.log('Notes cache loaded from the file') } - catch(e) { + catch (e) { console.trace('Could not load Notes cache from the file') console.error(e) - } + } } if (!notesCache) { diff --git a/src/query.ts b/src/query.ts index e6d0f5b..1bb8d2a 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,4 +1,5 @@ -import { stripSurroundingQuotes } from './utils' +import { settings } from './settings' +import { removeDiacritics, stripSurroundingQuotes } from './utils' import { parseQuery } from './vendor/parse-query' type QueryToken = { @@ -21,6 +22,7 @@ export class Query { public exclusions: QueryToken[] = [] constructor(text = '') { + if (settings.ignoreDiacritics) text = removeDiacritics(text) const tokens = parseQuery(text.toLowerCase(), { tokenize: true }) this.exclusions = tokens.exclude.text .map(this.formatToken) @@ -48,5 +50,3 @@ export class Query { } } } - - diff --git a/src/search.ts b/src/search.ts index 0b2c8ab..461b6ac 100644 --- a/src/search.ts +++ b/src/search.ts @@ -27,7 +27,7 @@ import { getNonExistingNotesFromCache, loadNotesCache, saveNotesCacheToFile, - isCacheOutdated + isCacheOutdated, } from './notes' let minisearchInstance: MiniSearch @@ -53,7 +53,7 @@ const tokenize = (text: string): string[] => { export async function initGlobalSearchIndex(): Promise { const options = { tokenize, - processTerm: term => + processTerm: (term: string) => settings.ignoreDiacritics ? removeDiacritics(term) : term, idField: 'path', fields: [ @@ -66,19 +66,22 @@ export async function initGlobalSearchIndex(): Promise { ], } - if (settings.storeIndexInFile && await app.vault.adapter.exists(searchIndexFilePath)) { + if ( + settings.storeIndexInFile && + (await app.vault.adapter.exists(searchIndexFilePath)) + ) { try { const json = await app.vault.adapter.read(searchIndexFilePath) minisearchInstance = MiniSearch.loadJSON(json, options) console.log('MiniSearch index loaded from the file') await loadNotesCache() } - catch(e) { + catch (e) { console.trace('Could not load MiniSearch index from the file') console.error(e) } } - + if (!minisearchInstance) { minisearchInstance = new MiniSearch(options) resetNotesCache() @@ -94,7 +97,8 @@ export async function initGlobalSearchIndex(): Promise { if (settings.storeIndexInFile) { files = allFiles.filter(file => isCacheOutdated(file)) notesSuffix = 'modified notes' - } else { + } + else { files = allFiles notesSuffix = 'notes' } @@ -116,8 +120,8 @@ export async function initGlobalSearchIndex(): Promise { if (files.length > 0) { const message = `Omnisearch - Indexed ${files.length} ${notesSuffix} in ${ - new Date().getTime() - start - }ms` + new Date().getTime() - start + }ms` console.log(message) diff --git a/src/settings.ts b/src/settings.ts index 5e3d369..45f7892 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -71,17 +71,17 @@ export class SettingsTab extends PluginSettingTab { ) // Ignore diacritics - // new Setting(containerEl) - // .setName('Ignore diacritics') - // .setDesc( - // 'Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky". Needs a restart to take effect.', - // ) - // .addToggle(toggle => - // toggle.setValue(settings.ignoreDiacritics).onChange(async v => { - // settings.ignoreDiacritics = v - // await saveSettings(this.plugin) - // }), - // ) + new Setting(containerEl) + .setName('Ignore diacritics') + .setDesc( + 'EXPERIMENTAL - Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky". Needs a restart to take effect.', + ) + .addToggle(toggle => + toggle.setValue(settings.ignoreDiacritics).onChange(async v => { + settings.ignoreDiacritics = v + await saveSettings(this.plugin) + }), + ) new Setting(containerEl) .setName('Store index in file') @@ -194,7 +194,7 @@ export class SettingsTab extends PluginSettingTab { export const DEFAULT_SETTINGS: OmnisearchSettings = { respectExcluded: true, reindexInRealTime: false, - ignoreDiacritics: true, + ignoreDiacritics: false, showIndexingNotices: false, showShortName: false,