From 3bd300160e1e4652c9b7db11e3615a89983b316f Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 4 May 2022 08:53:02 +0200 Subject: [PATCH] Feature/2 ignore folders (#42) * Updated README * #2 - using Obsidian's "Excluded files" setting to downrank results * #2 - using the correct api --- src/search.ts | 8 +++++++- src/types.d.ts | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/types.d.ts diff --git a/src/search.ts b/src/search.ts index c009e36..4c82a4b 100644 --- a/src/search.ts +++ b/src/search.ts @@ -76,6 +76,13 @@ async function search(query: Query): Promise { }, }) + // Half the score for files that are in Obsidian's excluded list + results.forEach(result => { + if (app.metadataCache.isUserIgnored(result.id)) { + result.score /= 3 // TODO: make this value configurable or toggleable? + } + }) + // If the search query contains quotes, filter out results that don't have the exact match const exactTerms = query.getExactTerms() if (exactTerms.length) { @@ -183,7 +190,6 @@ export async function addToIndex(file: TAbstractFile): Promise { try { // console.log(`Omnisearch - adding ${file.path} to index`) const fileCache = app.metadataCache.getFileCache(file) - // console.log(fileCache) if (indexedNotes[file.path]) { throw new Error(`${file.basename} is already indexed`) diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..a46c2d6 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,7 @@ +import { type MetadataCache } from 'obsidian' + +declare module 'obsidian' { + interface MetadataCache { + isUserIgnored(path:string):boolean + } +}