Add ability to downrank some folders in the results (#350)

* add downrankedFoldersFilters to settings

* use downrankedFoldersFilters to downrank some files without excluding them in obsidian, which also prevents tags from being indexed

* change hotkey for toggling excerpts to ctrl-g

* change var to let for proper scoping

* trim folders after splitting them

* only log downranking when we actually do it

* format with Prettier

* make prompt-instruction-command still ctrl g for now
This commit is contained in:
eegrok
2024-03-15 06:36:23 +13:00
committed by GitHub
parent c66c65cdc2
commit 72cb4216c0
3 changed files with 56 additions and 1 deletions

View File

@@ -252,6 +252,40 @@ export class Omnisearch {
})
}
logDebug(
'searching with downranked folders',
settings.downrankedFoldersFilters
)
// downrank files that are in folders listed in the downrankedFoldersFilters
if (settings.downrankedFoldersFilters.length > 0) {
results.forEach(result => {
const path = result.id
let downrankingFolder = false
settings.downrankedFoldersFilters.forEach(filter => {
if (path.startsWith(filter)) {
// we don't want the filter to match the folder sources, e.g.
// it needs to match a whole folder name
if (path === filter || path.startsWith(filter + '/')) {
logDebug('searching with downranked folders in path: ', path)
downrankingFolder = true
}
}
})
if (downrankingFolder) {
result.score /= 10
}
const pathParts = path.split('/')
const pathPartsLength = pathParts.length
for (let i = 0; i < pathPartsLength; i++) {
const pathPart = pathParts[i]
if (settings.downrankedFoldersFilters.includes(pathPart)) {
result.score /= 10
break
}
}
})
}
// Extract tags from the query
const tags = query.getTags()