Squashed commit of the following:

commit 739f9c349031510e8ef010ba2445a2a1fdbec247
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 16:57:03 2022 +0200

    Code cleaning + README

commit 85762bae592f3eafd34ba22b0cf1841bfbd91ca6
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 14:59:01 2022 +0200

    Cleaning deleted PDFs from cache

commit 1a37bf38d3f64870d4b40df1b67d8106c893ab64
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 13:18:06 2022 +0200

    PDF cache saved to IndexedDB
This commit is contained in:
Simon Cambier
2022-10-16 16:58:10 +02:00
parent ad820cb2c9
commit 1c3cc728f6
13 changed files with 184 additions and 124 deletions

View File

@@ -2,33 +2,25 @@ import { Notice } from 'obsidian'
import MiniSearch, { type Options, type SearchResult } from 'minisearch'
import {
chsRegex,
type IndexedNote,
type IndexedDocument,
type ResultNote,
minisearchCacheFilePath,
type SearchMatch,
SPACE_OR_PUNCTUATION,
} from './globals'
import {
isFileIndexable,
isFilePlaintext,
removeDiacritics,
stringsToRegex,
stripMarkdownCharacters,
wait,
} from './utils'
import type { Query } from './query'
import { settings } from './settings'
// import {
// getNoteFromCache,
// isCacheOutdated,
// loadNotesCache,
// resetNotesCache,
// } from './notes'
import * as NotesIndex from './notes-index'
import PQueue from 'p-queue-compat'
import pLimit from 'p-limit'
import { cacheManager } from './cache-manager'
export let minisearchInstance: MiniSearch<IndexedNote>
export let minisearchInstance: MiniSearch<IndexedDocument>
const tokenize = (text: string): string[] => {
const tokens = text.split(SPACE_OR_PUNCTUATION)
@@ -46,7 +38,7 @@ const tokenize = (text: string): string[] => {
* and adds all the notes to the index
*/
export async function initGlobalSearchIndex(): Promise<void> {
const options: Options<IndexedNote> = {
const options: Options<IndexedDocument> = {
tokenize,
processTerm: (term: string) =>
(settings.ignoreDiacritics ? removeDiacritics(term) : term).toLowerCase(),
@@ -106,15 +98,16 @@ export async function initGlobalSearchIndex(): Promise<void> {
}
// Read and index all the files into the search engine
const queue = new PQueue({ concurrency: 10 })
const queue = pLimit(10)
const input = []
for (const file of files) {
if (cacheManager.getNoteFromCache(file.path)) {
NotesIndex.removeFromIndex(file.path)
}
queue.add(() => NotesIndex.addToIndexAndCache(file))
input.push(queue(() => NotesIndex.addToIndexAndCache(file)))
}
await queue.onEmpty()
await Promise.all(input)
if (files.length > 0) {
const message = `Omnisearch - Indexed ${files.length} ${notesSuffix} in ${