Squashed commit of the following:
commit ac82511ddd17d5472ae3cfea9bbad9754f5a4d62 Author: Simon Cambier <simon.cambier@protonmail.com> Date: Sat Oct 22 08:23:42 2022 +0200 Screw that cache, seriously. commit 8ba40d1be73daaaffea09e07bc56c339266db9b6 Author: Simon Cambier <simon.cambier@protonmail.com> Date: Fri Oct 21 22:36:48 2022 +0200 Stuff commit 27b8fd7dc809be9714a109d3a458eb1276a47e2e Author: Simon Cambier <simon.cambier@protonmail.com> Date: Fri Oct 21 22:22:20 2022 +0200 Moved files commit fb1349c914907e586e103ca54fb04b9ddd45ef5d Author: Simon Cambier <simon.cambier@protonmail.com> Date: Thu Oct 20 22:25:29 2022 +0200 Removed duplicate code commit e7371138e60cbe4155cfd4fb44e3ee1d2e3ee088 Author: Simon Cambier <simon.cambier@protonmail.com> Date: Thu Oct 20 21:50:09 2022 +0200 Moved a bunch of files commit 2ee1b2a0e799d4b41ab3a444d8cc44dfff5b5623 Author: Simon Cambier <simon.cambier@protonmail.com> Date: Thu Oct 20 21:32:21 2022 +0200 Removed useless code commit 76c530dfb9adbad1bbe9079de2330fe43a044249 Author: Simon Cambier <simon.cambier@protonmail.com> Date: Thu Oct 20 20:44:11 2022 +0200 Split file reading and indexing
This commit is contained in:
66
src/main.ts
66
src/main.ts
@@ -1,29 +1,26 @@
|
||||
import { Notice, Plugin, TFile } from 'obsidian'
|
||||
import * as Search from './search'
|
||||
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
||||
import * as Search from './search/search'
|
||||
import {
|
||||
OmnisearchInFileModal,
|
||||
OmnisearchVaultModal,
|
||||
} from './components/modals'
|
||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||
import { eventBus, EventNames } from './globals'
|
||||
import { registerAPI } from '@vanakat/plugin-api'
|
||||
import api from './api'
|
||||
import { loadSearchHistory } from './search-history'
|
||||
import { isFilePlaintext } from './utils'
|
||||
import api from './tools/api'
|
||||
import { loadSearchHistory } from './search/search-history'
|
||||
import { isFilePlaintext } from './tools/utils'
|
||||
import * as NotesIndex from './notes-index'
|
||||
import { cacheManager } from './cache-manager'
|
||||
|
||||
function _registerAPI(plugin: OmnisearchPlugin): void {
|
||||
registerAPI('omnisearch', api, plugin as any)
|
||||
;(app as any).plugins.plugins.omnisearch.api = api
|
||||
plugin.register(() => {
|
||||
delete (app as any).plugins.plugins.omnisearch.api
|
||||
})
|
||||
}
|
||||
import * as FileLoader from './file-loader'
|
||||
|
||||
export default class OmnisearchPlugin extends Plugin {
|
||||
async onload(): Promise<void> {
|
||||
await cleanOldCacheFiles()
|
||||
await loadSettings(this)
|
||||
await loadSearchHistory()
|
||||
await cacheManager.loadNotesCache()
|
||||
|
||||
// Initialize minisearch
|
||||
await Search.initSearchEngine()
|
||||
|
||||
_registerAPI(this)
|
||||
|
||||
@@ -69,7 +66,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
)
|
||||
this.registerEvent(
|
||||
this.app.vault.on('modify', async file => {
|
||||
NotesIndex.addNoteToReindex(file)
|
||||
NotesIndex.markNoteForReindex(file)
|
||||
})
|
||||
)
|
||||
this.registerEvent(
|
||||
@@ -81,7 +78,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
})
|
||||
)
|
||||
|
||||
await Search.initGlobalSearchIndex()
|
||||
await populateIndex()
|
||||
})
|
||||
|
||||
// showWelcomeNotice(this)
|
||||
@@ -99,11 +96,36 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the files and feed them to Minisearch
|
||||
*/
|
||||
async function populateIndex(): Promise<void> {
|
||||
// Load plain text files
|
||||
console.time('Omnisearch - Timing')
|
||||
const files = await FileLoader.getPlainTextFiles()
|
||||
// Index them
|
||||
await Search.addAllToMinisearch(files)
|
||||
console.log(`Omnisearch - Indexed ${files.length} notes`)
|
||||
console.timeEnd('Omnisearch - Timing')
|
||||
|
||||
// Load PDFs
|
||||
if (settings.PDFIndexing) {
|
||||
console.time('Omnisearch - Timing')
|
||||
const pdfs = await FileLoader.getPDFFiles()
|
||||
// Index them
|
||||
await Search.addAllToMinisearch(pdfs)
|
||||
console.log(`Omnisearch - Indexed ${pdfs.length} PDFs`)
|
||||
console.timeEnd('Omnisearch - Timing')
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanOldCacheFiles() {
|
||||
const toDelete = [
|
||||
`${app.vault.configDir}/plugins/omnisearch/searchIndex.json`,
|
||||
`${app.vault.configDir}/plugins/omnisearch/notesCache.json`,
|
||||
`${app.vault.configDir}/plugins/omnisearch/pdfCache.data`
|
||||
`${app.vault.configDir}/plugins/omnisearch/notesCache.data`,
|
||||
`${app.vault.configDir}/plugins/omnisearch/searchIndex.data`,
|
||||
`${app.vault.configDir}/plugins/omnisearch/pdfCache.data`,
|
||||
]
|
||||
for (const item of toDelete) {
|
||||
if (await app.vault.adapter.exists(item)) {
|
||||
@@ -130,3 +152,11 @@ New beta feature: PDF search 🔎📄
|
||||
|
||||
plugin.saveData(settings)
|
||||
}
|
||||
|
||||
function _registerAPI(plugin: OmnisearchPlugin): void {
|
||||
registerAPI('omnisearch', api, plugin as any)
|
||||
;(app as any).plugins.plugins.omnisearch.api = api
|
||||
plugin.register(() => {
|
||||
delete (app as any).plugins.plugins.omnisearch.api
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user