diff --git a/src/database.ts b/src/database.ts index b1e1199..d3500b8 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,6 +1,7 @@ import Dexie from 'dexie' import type { AsPlainObject } from 'minisearch' import type { DocumentRef } from './globals' +import { Notice } from 'obsidian' export class OmnisearchCache extends Dexie { public static readonly dbVersion = 8 @@ -57,6 +58,7 @@ export class OmnisearchCache extends Dexie { } public async clearCache() { + new Notice('Omnisearch - Cache cleared. Please restart Obsidian.') await this.minisearch.clear() } } diff --git a/src/settings.ts b/src/settings.ts index 249ec24..7ddd502 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -100,31 +100,36 @@ export class SettingsTab extends PluginSettingTab { //#region Indexing - new Setting(containerEl).setName('Indexing').setHeading() - - const textExtractDesc = new DocumentFragment() - if (getTextExtractor()) { - textExtractDesc.createSpan({}, span => { - span.innerHTML = `👍 You have installed Text Extractor, Omnisearch will use it to index PDFs and images. + const indexingDesc = new DocumentFragment() + indexingDesc.createSpan({}, span => { + span.innerHTML = `⚠️ Changing indexing settings will clear the cache, and requires a restart of Obsidian.

` + if (getTextExtractor()) { + span.innerHTML += ` + 👍 You have installed Text Extractor, Omnisearch can use it to index PDFs and images contents.
Text extraction only works on desktop, but the cache can be synchronized with your mobile device.` - }) - } else { - textExtractDesc.createSpan({}, span => { - span.innerHTML = `⚠️ Omnisearch requires Text Extractor to index PDFs and images.` - }) - } - new Setting(containerEl).setDesc(textExtractDesc) + } else { + span.innerHTML += `⚠️ Omnisearch requires Text Extractor to index PDFs and images.` + } + }) + + new Setting(containerEl) + .setName('Indexing') + .setHeading() + .setDesc(indexingDesc) // PDF Indexing const indexPDFsDesc = new DocumentFragment() indexPDFsDesc.createSpan({}, span => { - span.innerHTML = `Include PDFs in search results` + span.innerHTML = `Omnisearch will use Text Extractor to index the content of your PDFs` }) new Setting(containerEl) - .setName(`PDFs Indexing ${getTextExtractor() ? '' : '⚠️ Disabled'}`) + .setName( + `PDFs content indexing ${getTextExtractor() ? '' : '⚠️ Disabled'}` + ) .setDesc(indexPDFsDesc) .addToggle(toggle => toggle.setValue(settings.PDFIndexing).onChange(async v => { + await database.clearCache() settings.PDFIndexing = v await saveSettings(this.plugin) }) @@ -134,27 +139,49 @@ export class SettingsTab extends PluginSettingTab { // Images Indexing const indexImagesDesc = new DocumentFragment() indexImagesDesc.createSpan({}, span => { - span.innerHTML = `Include images in search results` + span.innerHTML = `Omnisearch will use Text Extractor to OCR your images and index their content` }) new Setting(containerEl) - .setName(`Images Indexing ${getTextExtractor() ? '' : '⚠️ Disabled'}`) + .setName(`Images OCR indexing ${getTextExtractor() ? '' : '⚠️ Disabled'}`) .setDesc(indexImagesDesc) .addToggle(toggle => toggle.setValue(settings.imagesIndexing).onChange(async v => { + await database.clearCache() settings.imagesIndexing = v await saveSettings(this.plugin) }) ) .setDisabled(!getTextExtractor()) + // Index filenames of unsupported files + const indexUnsupportedDesc = new DocumentFragment() + indexUnsupportedDesc.createSpan({}, span => { + span.innerHTML = ` + Omnisearch can index filenames of "unsupported" files, such as e.g.
.mp4
,
.xlsx
, + or non-extracted PDFs & images.
+ "Obsidian setting" will respect the value of "Files & Links > Detect all file extensions"` + }) + new Setting(containerEl) + .setName('Index paths of unsupported files') + .setDesc(indexUnsupportedDesc) + .addDropdown(dropdown => { + dropdown + .addOptions({ yes: 'Yes', no: 'No', default: 'Obsidian setting' }) + .setValue(settings.unsupportedFilesIndexing) + .onChange(async v => { + await database.clearCache() + ;(settings.unsupportedFilesIndexing as any) = v + await saveSettings(this.plugin) + }) + }) + // Additional text files to index const indexedFileTypesDesc = new DocumentFragment() indexedFileTypesDesc.createSpan({}, span => { span.innerHTML = `In addition to standard md files, Omnisearch can also index other PLAINTEXT files.
Add extensions separated by a space, without the dot. Example: "txt org csv".
⚠️ Using extensions of non-plaintext files (like .docx or .pptx) WILL cause crashes, - because Omnisearch will try to index their content.
- ${needsARestart}` + because Omnisearch will try to index their content.` }) new Setting(containerEl) .setName('Additional TEXT files to index') @@ -164,32 +191,12 @@ export class SettingsTab extends PluginSettingTab { .setValue(settings.indexedFileTypes.join(' ')) .setPlaceholder('Example: txt org csv') .onChange(async v => { + await database.clearCache() settings.indexedFileTypes = v.split(' ') await saveSettings(this.plugin) }) }) - // Unsupported files - const indexUnsupportedDesc = new DocumentFragment() - indexUnsupportedDesc.createSpan({}, span => { - span.innerHTML = ` - Omnisearch can index filenames of "unsupported" files, such as e.g.
.mp4
or
.xlsx
.
- "Obsidian setting" will respect the value of "Files & Links > Detect all file extensions". -
${needsARestart}` - }) - new Setting(containerEl) - .setName('Index unsupported files') - .setDesc(indexUnsupportedDesc) - .addDropdown(dropdown => { - dropdown - .addOptions({ yes: 'Yes', no: 'No', default: 'Obsidian setting' }) - .setValue(settings.unsupportedFilesIndexing) - .onChange(async v => { - ;(settings.unsupportedFilesIndexing as any) = v - await saveSettings(this.plugin) - }) - }) - //#endregion Indexing //#region Behavior @@ -409,7 +416,9 @@ export class SettingsTab extends PluginSettingTab { .addSlider(cb => this.weightSlider(cb, 'weightH3')) new Setting(containerEl) - .setName(`Tags without the # (default: ${DEFAULT_SETTINGS.weightUnmarkedTags})`) + .setName( + `Tags without the # (default: ${DEFAULT_SETTINGS.weightUnmarkedTags})` + ) .addSlider(cb => this.weightSlider(cb, 'weightUnmarkedTags')) //#endregion Results Weighting @@ -488,7 +497,6 @@ export class SettingsTab extends PluginSettingTab { cb.setButtonText('Clear cache') cb.onClick(async () => { await database.clearCache() - new Notice('Omnisearch - Cache cleared. Please restart Obsidian.') }) }) } diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 49b11f1..9a900f5 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -278,12 +278,10 @@ export function isContentIndexable(path: string): boolean { export function isFilenameIndexable(path: string): boolean { return ( - canIndexUnsupportedFiles() || + (canIndexUnsupportedFiles()) || isFilePlaintext(path) || isFileCanvas(path) || - isFileFromDataloomPlugin(path) || - isFilePDF(path) || - isFileImage(path) + isFileFromDataloomPlugin(path) ) }