Feature/2 ignore folders (#42)

* Updated README

* #2 - using Obsidian's "Excluded files" setting to downrank results

* #2 - using the correct api
This commit is contained in:
Simon Cambier
2022-05-04 08:53:02 +02:00
committed by GitHub
parent 7d0b5c0c82
commit 3bd300160e
2 changed files with 14 additions and 1 deletions

View File

@@ -76,6 +76,13 @@ async function search(query: Query): Promise<SearchResult[]> {
},
})
// 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<void> {
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`)

7
src/types.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
import { type MetadataCache } from 'obsidian'
declare module 'obsidian' {
interface MetadataCache {
isUserIgnored(path:string):boolean
}
}