diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index 4f719be..fe2d17c 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -144,6 +144,9 @@ } function switchToInFileModal(): void { + if (selectedNote.path.endsWith('.pdf')) { + return + } saveCurrentQuery() modal.close() if (selectedNote) { diff --git a/src/search.ts b/src/search.ts index cde70f2..0c22cd9 100644 --- a/src/search.ts +++ b/src/search.ts @@ -42,7 +42,7 @@ const tokenize = (text: string): string[] => { * Initializes the MiniSearch instance, * and adds all the notes to the index */ -export async function initGlobalSearchIndex(): Promise { +export async function initGlobalSearchIndex(force = false): Promise { const options: Options = { tokenize, processTerm: (term: string) => @@ -76,7 +76,7 @@ export async function initGlobalSearchIndex(): Promise { } } - if (!minisearchInstance) { + if (!minisearchInstance || force) { minisearchInstance = new MiniSearch(options) resetNotesCache() } diff --git a/src/settings.ts b/src/settings.ts index 70908ee..88885c3 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -2,6 +2,7 @@ import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian' import { writable } from 'svelte/store' import { notesCacheFilePath, searchIndexFilePath } from './globals' import type OmnisearchPlugin from './main' +import { initGlobalSearchIndex } from './search' interface WeightingSettings { weightBasename: number @@ -14,6 +15,7 @@ export interface OmnisearchSettings extends WeightingSettings { respectExcluded: boolean ignoreDiacritics: boolean indexedFileTypes: string[] + indexPDFs: boolean storeIndexInFile: boolean showIndexingNotices: boolean @@ -71,7 +73,7 @@ export class SettingsTab extends PluginSettingTab { const diacriticsDesc = new DocumentFragment() diacriticsDesc.createSpan({}, span => { span.innerHTML = `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 fully take effect.` + Changing this will trigger a full reindex.` }) new Setting(containerEl) .setName('Ignore diacritics') @@ -80,6 +82,7 @@ export class SettingsTab extends PluginSettingTab { toggle.setValue(settings.ignoreDiacritics).onChange(async v => { settings.ignoreDiacritics = v await saveSettings(this.plugin) + await initGlobalSearchIndex(true) }) ) @@ -104,6 +107,23 @@ export class SettingsTab extends PluginSettingTab { }) }) + // Index PDFs + const indexPDFsDesc = new DocumentFragment() + indexPDFsDesc.createSpan({}, span => { + span.innerHTML = `Omnisearch will index your PDFs, and return them in search results. + This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.
+ Changing this will trigger a full reindex.` + }) + new Setting(containerEl) + .setName('BETA - Index PDFs') + .setDesc(indexPDFsDesc) + .addToggle(toggle => + toggle.setValue(settings.indexPDFs).onChange(async v => { + settings.indexPDFs = v + await saveSettings(this.plugin) + await initGlobalSearchIndex(true) + }) + ) // Store index const serializedIndexDesc = new DocumentFragment() serializedIndexDesc.createSpan({}, span => { @@ -111,11 +131,11 @@ export class SettingsTab extends PluginSettingTab { This results in faster loading times for bigger vaults and mobile devices.
⚠️ Note: the index can become corrupted - if you notice any issue, disable and re-enable this option to clear the cache.
⚠️ Cache files in .obsidian/plugins/omnisearch/ must not be synchronized.
- Needs a restart to fully take effect. + Changing this will trigger a full reindex. ` }) new Setting(containerEl) - .setName('EXPERIMENTAL - Store index in file') + .setName('Store index in file') .setDesc(serializedIndexDesc) .addToggle(toggle => toggle.setValue(settings.storeIndexInFile).onChange(async v => { @@ -123,6 +143,7 @@ export class SettingsTab extends PluginSettingTab { await app.vault.adapter.remove(searchIndexFilePath) settings.storeIndexInFile = v await saveSettings(this.plugin) + await initGlobalSearchIndex(true) }) ) @@ -270,6 +291,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = { respectExcluded: true, ignoreDiacritics: true, indexedFileTypes: [] as string[], + indexPDFs: false, showIndexingNotices: false, showShortName: false, diff --git a/src/utils.ts b/src/utils.ts index 430d445..492050a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -115,8 +115,8 @@ function mapAsync( /** * https://stackoverflow.com/a/53508547 - * @param arr - * @param callback + * @param array + * @param callbackfn * @returns */ export async function filterAsync( @@ -174,7 +174,7 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' { export function isFileIndexable(path: string): boolean { return ( - path.endsWith('.md') || path.endsWith('.pdf') || + path.endsWith('.md') || (settings.indexPDFs && path.endsWith('.pdf')) || settings.indexedFileTypes.some(t => path.endsWith(`.${t}`)) ) }