PDF indexing is an opt-in

This commit is contained in:
Simon Cambier
2022-09-30 22:30:41 +02:00
parent 5d1e1da45b
commit e9efed270f
4 changed files with 33 additions and 8 deletions

View File

@@ -144,6 +144,9 @@
}
function switchToInFileModal(): void {
if (selectedNote.path.endsWith('.pdf')) {
return
}
saveCurrentQuery()
modal.close()
if (selectedNote) {

View File

@@ -42,7 +42,7 @@ const tokenize = (text: string): string[] => {
* Initializes the MiniSearch instance,
* 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> = {
tokenize,
processTerm: (term: string) =>
@@ -76,7 +76,7 @@ export async function initGlobalSearchIndex(): Promise<void> {
}
}
if (!minisearchInstance) {
if (!minisearchInstance || force) {
minisearchInstance = new MiniSearch(options)
resetNotesCache()
}

View File

@@ -2,6 +2,7 @@ import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
import { writable } from 'svelte/store'
import { notesCacheFilePath, searchIndexFilePath } from './globals'
import type OmnisearchPlugin from './main'
import { initGlobalSearchIndex } from './search'
interface WeightingSettings {
weightBasename: number
@@ -14,6 +15,7 @@ export interface OmnisearchSettings extends WeightingSettings {
respectExcluded: boolean
ignoreDiacritics: boolean
indexedFileTypes: string[]
indexPDFs: boolean
storeIndexInFile: boolean
showIndexingNotices: boolean
@@ -71,7 +73,7 @@ export class SettingsTab extends PluginSettingTab {
const diacriticsDesc = new DocumentFragment()
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/>
<strong>Needs a restart to fully take effect.</strong>`
<strong>Changing this will trigger a full reindex.</strong>`
})
new Setting(containerEl)
.setName('Ignore diacritics')
@@ -80,6 +82,7 @@ export class SettingsTab extends PluginSettingTab {
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
settings.ignoreDiacritics = v
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
const serializedIndexDesc = new DocumentFragment()
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 />
<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/>
<strong>Needs a restart to fully take effect.</strong>
<strong>Changing this will trigger a full reindex.</strong>
`
})
new Setting(containerEl)
.setName('EXPERIMENTAL - Store index in file')
.setName('Store index in file')
.setDesc(serializedIndexDesc)
.addToggle(toggle =>
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
@@ -123,6 +143,7 @@ export class SettingsTab extends PluginSettingTab {
await app.vault.adapter.remove(searchIndexFilePath)
settings.storeIndexInFile = v
await saveSettings(this.plugin)
await initGlobalSearchIndex(true)
})
)
@@ -270,6 +291,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
respectExcluded: true,
ignoreDiacritics: true,
indexedFileTypes: [] as string[],
indexPDFs: false,
showIndexingNotices: false,
showShortName: false,

View File

@@ -115,8 +115,8 @@ function mapAsync<T, U>(
/**
* https://stackoverflow.com/a/53508547
* @param arr
* @param callback
* @param array
* @param callbackfn
* @returns
*/
export async function filterAsync<T>(
@@ -174,7 +174,7 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
export function isFileIndexable(path: string): boolean {
return (
path.endsWith('.md') || path.endsWith('.pdf') ||
path.endsWith('.md') || (settings.indexPDFs && path.endsWith('.pdf')) ||
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
)
}