This commit is contained in:
Simon Cambier
2022-12-08 21:09:18 +01:00
parent 67d9a807c4
commit 98e343e33e
7 changed files with 196 additions and 184 deletions

View File

@@ -1,6 +1,6 @@
import Dexie from 'dexie'
import type { AsPlainObject } from 'minisearch'
import type { DocumentRef, IndexedDocument } from './globals'
import type { DocumentRef } from './globals'
export class OmnisearchCache extends Dexie {
public static readonly dbVersion = 8

View File

@@ -1,35 +1,33 @@
import type { TAbstractFile } from 'obsidian'
import { removeAnchors } from './tools/notes'
import type { IndexedDocument } from './globals'
import { searchEngine } from './search/omnisearch'
/**
* Index a non-existing note.
* Useful to find internal links that lead (yet) to nowhere
* @param name
* @param parent The note referencing the
*/
export function addNonExistingToIndex(name: string, parent: string): void {
name = removeAnchors(name)
const filename = name + (name.endsWith('.md') ? '' : '.md')
const note: IndexedDocument = {
path: filename,
basename: name,
mtime: 0,
content: '',
tags: [],
aliases: '',
headings1: '',
headings2: '',
headings3: '',
doesNotExist: true,
parent,
}
// searchEngine.addDocuments([note])
}
// /**
// * Index a non-existing note.
// * Useful to find internal links that lead (yet) to nowhere
// * @param name
// * @param parent The note referencing the
// */
// export function addNonExistingToIndex(name: string, parent: string): void {
// name = removeAnchors(name)
// const filename = name + (name.endsWith('.md') ? '' : '.md')
//
// const note: IndexedDocument = {
// path: filename,
// basename: name,
// mtime: 0,
//
// content: '',
// tags: [],
// aliases: '',
// headings1: '',
// headings2: '',
// headings3: '',
//
// doesNotExist: true,
// parent,
// }
// // searchEngine.addDocuments([note])
// }
const notesToReindex = new Set<TAbstractFile>()

View File

@@ -5,13 +5,7 @@ import type {
ResultNote,
SearchMatch,
} from '../globals'
import {
chsRegex,
chsSegmenter,
indexingStep,
IndexingStepType,
SPACE_OR_PUNCTUATION,
} from '../globals'
import { chsRegex, chsSegmenter, SPACE_OR_PUNCTUATION } from '../globals'
import { settings } from '../settings'
import {
chunkArray,
@@ -81,7 +75,6 @@ export class Omnisearch {
toAdd: DocumentRef[]
toRemove: DocumentRef[]
} {
const indexedArr = [...this.indexedDocuments]
const docsMap = new Map(docs.map(d => [d.path, d.mtime]))
const toAdd = docs.filter(

19
src/stores/results.ts Normal file
View File

@@ -0,0 +1,19 @@
import type { ResultNote } from 'src/globals'
import { writable } from 'svelte/store'
function createSearchResultsStore() {
const { subscribe, set, update } = writable<ResultNote[]>([])
return {
subscribe,
add: (item: ResultNote) =>
update(arr => {
arr.push(item)
return arr
}),
set: (items: ResultNote[]) => set(items),
reset: () => set([]),
}
}
export const searchResultsStore = createSearchResultsStore()