#127 - Downrank or hide excluded files

This commit is contained in:
Simon Cambier
2022-12-03 09:42:24 +01:00
parent a096969c0f
commit c33d6e0cee
2 changed files with 18 additions and 7 deletions

View File

@@ -172,8 +172,18 @@ export class Omnisearch {
}) })
if (!results.length) return this.previousResults if (!results.length) return this.previousResults
// Downrank files that are in Obsidian's excluded list // Hide or downrank files that are in Obsidian's excluded list
if (settings.respectExcluded) { if (settings.hideExcluded) {
// Filter the files out
results = results.filter(
result =>
!(
app.metadataCache.isUserIgnored &&
app.metadataCache.isUserIgnored(result.id)
)
)
} else {
// Just downrank them
results.forEach(result => { results.forEach(result => {
if ( if (
app.metadataCache.isUserIgnored && app.metadataCache.isUserIgnored &&

View File

@@ -19,7 +19,7 @@ interface WeightingSettings {
export interface OmnisearchSettings extends WeightingSettings { export interface OmnisearchSettings extends WeightingSettings {
/** Respect the "excluded files" Obsidian setting by downranking results ignored files */ /** Respect the "excluded files" Obsidian setting by downranking results ignored files */
respectExcluded: boolean hideExcluded: boolean
/** Ignore diacritics when indexing files */ /** Ignore diacritics when indexing files */
ignoreDiacritics: boolean ignoreDiacritics: boolean
/** Extensions of plain text files to index, in addition to .md */ /** Extensions of plain text files to index, in addition to .md */
@@ -158,11 +158,12 @@ export class SettingsTab extends PluginSettingTab {
new Setting(containerEl) new Setting(containerEl)
.setName('Respect Obsidian\'s "Excluded Files"') .setName('Respect Obsidian\'s "Excluded Files"')
.setDesc( .setDesc(
'Files that are in Obsidian\'s "Options > Files & Links > Excluded Files" list will be downranked in results.' `By default, fFiles that are in Obsidian\'s "Options > Files & Links > Excluded Files" list are downranked in results.
Enable this option to completely hide them`
) )
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(settings.respectExcluded).onChange(async v => { toggle.setValue(settings.hideExcluded).onChange(async v => {
settings.respectExcluded = v settings.hideExcluded = v
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -362,7 +363,7 @@ export class SettingsTab extends PluginSettingTab {
} }
export const DEFAULT_SETTINGS: OmnisearchSettings = { export const DEFAULT_SETTINGS: OmnisearchSettings = {
respectExcluded: true, hideExcluded: false,
ignoreDiacritics: true, ignoreDiacritics: true,
indexedFileTypes: [] as string[], indexedFileTypes: [] as string[],
PDFIndexing: false, PDFIndexing: false,