Merge branch 'develop' of https://github.com/scambier/obsidian-omnisearch into develop
This commit is contained in:
@@ -136,7 +136,7 @@ abstract class OmnisearchModal extends Modal {
|
||||
})
|
||||
|
||||
// Context
|
||||
this.scope.register(['Ctrl'], 'H', _e => {
|
||||
this.scope.register(['Ctrl'], 'G', _e => {
|
||||
eventBus.emit(EventNames.ToggleExcerpts)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ export interface OmnisearchSettings extends WeightingSettings {
|
||||
useCache: boolean
|
||||
/** Respect the "excluded files" Obsidian setting by downranking results ignored files */
|
||||
hideExcluded: boolean
|
||||
/** downrank files in the given folders */
|
||||
downrankedFoldersFilters: string[]
|
||||
/** Ignore diacritics when indexing files */
|
||||
ignoreDiacritics: boolean
|
||||
/** Extensions of plain text files to index, in addition to .md */
|
||||
@@ -268,6 +270,24 @@ export class SettingsTab extends PluginSettingTab {
|
||||
})
|
||||
)
|
||||
|
||||
// Downranked files
|
||||
new Setting(containerEl)
|
||||
.setName('Folders to downrank in search results')
|
||||
.setDesc(
|
||||
`Folders to downrank in search results. Files in these folders will be downranked in results. They will still be indexed for tags, unlike excluded files. Folders should be comma delimited.`
|
||||
)
|
||||
.addText(component => {
|
||||
component
|
||||
.setValue(settings.downrankedFoldersFilters.join(','))
|
||||
.setPlaceholder('Example: src,p2/dir')
|
||||
.onChange(async v => {
|
||||
let folders = v.split(',')
|
||||
folders = folders.map(f => f.trim())
|
||||
settings.downrankedFoldersFilters = folders
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
})
|
||||
|
||||
// Split CamelCaseWords
|
||||
const camelCaseDesc = new DocumentFragment()
|
||||
camelCaseDesc.createSpan({}, span => {
|
||||
@@ -621,6 +641,7 @@ export class SettingsTab extends PluginSettingTab {
|
||||
export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
||||
useCache: true,
|
||||
hideExcluded: false,
|
||||
downrankedFoldersFilters: [] as string[],
|
||||
ignoreDiacritics: true,
|
||||
indexedFileTypes: [] as string[],
|
||||
PDFIndexing: false,
|
||||
|
||||
Reference in New Issue
Block a user