From e618d4ca47590106fb3be1bd060305b7055f3ddb Mon Sep 17 00:00:00 2001 From: demig00d <28487425+demig00d@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:01:43 +0300 Subject: [PATCH] Index office documents (#340) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 👌 --- src/cache-manager.ts | 10 ++++++++++ src/settings.ts | 28 +++++++++++++++++++++++++--- src/tools/utils.ts | 5 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/cache-manager.ts b/src/cache-manager.ts index 26c22f7..372db26 100644 --- a/src/cache-manager.ts +++ b/src/cache-manager.ts @@ -13,6 +13,7 @@ import { isFileFromDataloomPlugin, isFileImage, isFilePDF, + isFileOffice, isFilePlaintext, isFilenameIndexable, logDebug, @@ -106,6 +107,15 @@ async function getAndMapIndexedDocument( content = await extractor.extractText(file) } + // ** Office document ** + else if ( + isFileOffice(path) && + settings.officeIndexing && + extractor?.canFileBeExtracted(path) + ) { + content = await extractor.extractText(file) + } + // ** Unsupported files ** else if (isFilenameIndexable(path)) { content = file.path diff --git a/src/settings.ts b/src/settings.ts index 8116504..5c103f5 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -37,6 +37,8 @@ export interface OmnisearchSettings extends WeightingSettings { PDFIndexing: boolean /** Enable Images indexing */ imagesIndexing: boolean + /** Enable Office documents indexing */ + officeIndexing: boolean /** Enable Excalidraw indexing */ excalidrawIndexing: boolean /** Enable indexing of unknown files */ @@ -160,11 +162,30 @@ export class SettingsTab extends PluginSettingTab { ) .setDisabled(!getTextExtractor()) + // Office Documents Indexing + const indexOfficesDesc = new DocumentFragment() + indexOfficesDesc.createSpan({}, span => { + span.innerHTML = `Omnisearch will use Text Extractor to index the content of your office documents (currently
.docxand
.xlsx)` + }) + new Setting(containerEl) + .setName( + `Documents content indexing ${getTextExtractor() ? '' : '⚠️ Disabled'}` + ) + .setDesc(indexOfficesDesc) + .addToggle(toggle => + toggle.setValue(settings.officeIndexing).onChange(async v => { + await database.clearCache() + settings.officeIndexing = 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, + Omnisearch can index filenames of "unsupported" files, such as e.g.
.mp4or non-extracted PDFs & images.
md files, Omnisearch can also index other PLAINTEXT files.txt org csv".