PDF indexing is an opt-in
This commit is contained in:
@@ -144,6 +144,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function switchToInFileModal(): void {
|
function switchToInFileModal(): void {
|
||||||
|
if (selectedNote.path.endsWith('.pdf')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
saveCurrentQuery()
|
saveCurrentQuery()
|
||||||
modal.close()
|
modal.close()
|
||||||
if (selectedNote) {
|
if (selectedNote) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const tokenize = (text: string): string[] => {
|
|||||||
* Initializes the MiniSearch instance,
|
* Initializes the MiniSearch instance,
|
||||||
* and adds all the notes to the index
|
* and adds all the notes to the index
|
||||||
*/
|
*/
|
||||||
export async function initGlobalSearchIndex(): Promise<void> {
|
export async function initGlobalSearchIndex(force = false): Promise<void> {
|
||||||
const options: Options<IndexedNote> = {
|
const options: Options<IndexedNote> = {
|
||||||
tokenize,
|
tokenize,
|
||||||
processTerm: (term: string) =>
|
processTerm: (term: string) =>
|
||||||
@@ -76,7 +76,7 @@ export async function initGlobalSearchIndex(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!minisearchInstance) {
|
if (!minisearchInstance || force) {
|
||||||
minisearchInstance = new MiniSearch(options)
|
minisearchInstance = new MiniSearch(options)
|
||||||
resetNotesCache()
|
resetNotesCache()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
|
|||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import { notesCacheFilePath, searchIndexFilePath } from './globals'
|
import { notesCacheFilePath, searchIndexFilePath } from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
|
import { initGlobalSearchIndex } from './search'
|
||||||
|
|
||||||
interface WeightingSettings {
|
interface WeightingSettings {
|
||||||
weightBasename: number
|
weightBasename: number
|
||||||
@@ -14,6 +15,7 @@ export interface OmnisearchSettings extends WeightingSettings {
|
|||||||
respectExcluded: boolean
|
respectExcluded: boolean
|
||||||
ignoreDiacritics: boolean
|
ignoreDiacritics: boolean
|
||||||
indexedFileTypes: string[]
|
indexedFileTypes: string[]
|
||||||
|
indexPDFs: boolean
|
||||||
storeIndexInFile: boolean
|
storeIndexInFile: boolean
|
||||||
|
|
||||||
showIndexingNotices: boolean
|
showIndexingNotices: boolean
|
||||||
@@ -71,7 +73,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
const diacriticsDesc = new DocumentFragment()
|
const diacriticsDesc = new DocumentFragment()
|
||||||
diacriticsDesc.createSpan({}, span => {
|
diacriticsDesc.createSpan({}, span => {
|
||||||
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
||||||
<strong>Needs a restart to fully take effect.</strong>`
|
<strong>Changing this will trigger a full reindex.</strong>`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Ignore diacritics')
|
.setName('Ignore diacritics')
|
||||||
@@ -80,6 +82,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
|
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
|
||||||
settings.ignoreDiacritics = v
|
settings.ignoreDiacritics = v
|
||||||
await saveSettings(this.plugin)
|
await saveSettings(this.plugin)
|
||||||
|
await initGlobalSearchIndex(true)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -104,6 +107,23 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Index PDFs
|
||||||
|
const indexPDFsDesc = new DocumentFragment()
|
||||||
|
indexPDFsDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `Omnisearch will index your PDFs, and return them in search results.
|
||||||
|
This feature is currently a work-in-progress, please report slowdowns or issues that you might experience.<br>
|
||||||
|
<strong>Changing this will trigger a full reindex.</strong>`
|
||||||
|
})
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('BETA - Index PDFs')
|
||||||
|
.setDesc(indexPDFsDesc)
|
||||||
|
.addToggle(toggle =>
|
||||||
|
toggle.setValue(settings.indexPDFs).onChange(async v => {
|
||||||
|
settings.indexPDFs = v
|
||||||
|
await saveSettings(this.plugin)
|
||||||
|
await initGlobalSearchIndex(true)
|
||||||
|
})
|
||||||
|
)
|
||||||
// Store index
|
// Store index
|
||||||
const serializedIndexDesc = new DocumentFragment()
|
const serializedIndexDesc = new DocumentFragment()
|
||||||
serializedIndexDesc.createSpan({}, span => {
|
serializedIndexDesc.createSpan({}, span => {
|
||||||
@@ -111,11 +131,11 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
This results in faster loading times for bigger vaults and mobile devices.<br />
|
This results in faster loading times for bigger vaults and mobile devices.<br />
|
||||||
<em>⚠️ Note: the index can become corrupted - if you notice any issue, disable and re-enable this option to clear the cache.</em><br/>
|
<em>⚠️ Note: the index can become corrupted - if you notice any issue, disable and re-enable this option to clear the cache.</em><br/>
|
||||||
<em>⚠️ Cache files in <code>.obsidian/plugins/omnisearch/</code> must not be synchronized.</em><br/>
|
<em>⚠️ Cache files in <code>.obsidian/plugins/omnisearch/</code> must not be synchronized.</em><br/>
|
||||||
<strong>Needs a restart to fully take effect.</strong>
|
<strong>Changing this will trigger a full reindex.</strong>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('EXPERIMENTAL - Store index in file')
|
.setName('Store index in file')
|
||||||
.setDesc(serializedIndexDesc)
|
.setDesc(serializedIndexDesc)
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
|
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
|
||||||
@@ -123,6 +143,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
await app.vault.adapter.remove(searchIndexFilePath)
|
await app.vault.adapter.remove(searchIndexFilePath)
|
||||||
settings.storeIndexInFile = v
|
settings.storeIndexInFile = v
|
||||||
await saveSettings(this.plugin)
|
await saveSettings(this.plugin)
|
||||||
|
await initGlobalSearchIndex(true)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -270,6 +291,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
|||||||
respectExcluded: true,
|
respectExcluded: true,
|
||||||
ignoreDiacritics: true,
|
ignoreDiacritics: true,
|
||||||
indexedFileTypes: [] as string[],
|
indexedFileTypes: [] as string[],
|
||||||
|
indexPDFs: false,
|
||||||
|
|
||||||
showIndexingNotices: false,
|
showIndexingNotices: false,
|
||||||
showShortName: false,
|
showShortName: false,
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ function mapAsync<T, U>(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* https://stackoverflow.com/a/53508547
|
* https://stackoverflow.com/a/53508547
|
||||||
* @param arr
|
* @param array
|
||||||
* @param callback
|
* @param callbackfn
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function filterAsync<T>(
|
export async function filterAsync<T>(
|
||||||
@@ -174,7 +174,7 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
|
|||||||
|
|
||||||
export function isFileIndexable(path: string): boolean {
|
export function isFileIndexable(path: string): boolean {
|
||||||
return (
|
return (
|
||||||
path.endsWith('.md') || path.endsWith('.pdf') ||
|
path.endsWith('.md') || (settings.indexPDFs && path.endsWith('.pdf')) ||
|
||||||
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
|
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user