Small rework
This commit is contained in:
@@ -14,7 +14,7 @@ if you want to view the source visit the plugins github repository
|
|||||||
*/
|
*/
|
||||||
`
|
`
|
||||||
|
|
||||||
const production = !process.env.ROLLUP_WATCH
|
const production = false//!process.env.ROLLUP_WATCH
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: './src/main.ts',
|
input: './src/main.ts',
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import { cacheManager } from 'src/cache-manager'
|
import { cacheManager } from 'src/cache-manager'
|
||||||
import { settings, showExcerpt } from 'src/settings'
|
import { settings, showExcerpt } from 'src/settings'
|
||||||
import type { ResultNote } from '../globals'
|
import type { ResultNote } from '../globals'
|
||||||
import * as Search from '../search'
|
|
||||||
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
|
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
|
||||||
import ResultItemContainer from './ResultItemContainer.svelte'
|
import ResultItemContainer from './ResultItemContainer.svelte'
|
||||||
|
|
||||||
@@ -10,7 +9,6 @@
|
|||||||
export let note: ResultNote
|
export let note: ResultNote
|
||||||
|
|
||||||
$: reg = stringsToRegex(note.foundWords)
|
$: reg = stringsToRegex(note.foundWords)
|
||||||
$: matches = Search.getMatches(note.content, reg)
|
|
||||||
$: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
|
$: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
|
||||||
$: glyph = cacheManager.getNoteFromMemCache(note.path)?.doesNotExist
|
$: glyph = cacheManager.getNoteFromMemCache(note.path)?.doesNotExist
|
||||||
$: title = settings.showShortName ? note.basename : note.path
|
$: title = settings.showShortName ? note.basename : note.path
|
||||||
@@ -27,9 +25,9 @@
|
|||||||
{@html title.replace(reg, highlighter)}
|
{@html title.replace(reg, highlighter)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{#if matches.length > 0}
|
{#if note.matches.length > 0}
|
||||||
<span class="omnisearch-result__counter">
|
<span class="omnisearch-result__counter">
|
||||||
{matches.length} {matches.length > 1 ? 'matches' : 'match'}
|
{note.matches.length} {note.matches.length > 1 ? 'matches' : 'match'}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import pLimit from 'p-limit'
|
||||||
import { EventBus } from './event-bus'
|
import { EventBus } from './event-bus'
|
||||||
|
import { settings } from './settings'
|
||||||
|
|
||||||
export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g
|
export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g
|
||||||
export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms
|
export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
// Listeners to keep the search index up-to-date
|
// Listeners to keep the search index up-to-date
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.vault.on('create', file => {
|
this.app.vault.on('create', file => {
|
||||||
NotesIndex.addToIndexAndCache(file)
|
NotesIndex.addToIndexAndMemCache(file)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
@@ -76,7 +76,7 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
this.app.vault.on('rename', async (file, oldPath) => {
|
this.app.vault.on('rename', async (file, oldPath) => {
|
||||||
if (file instanceof TFile && isFilePlaintext(file.path)) {
|
if (file instanceof TFile && isFilePlaintext(file.path)) {
|
||||||
NotesIndex.removeFromIndex(oldPath)
|
NotesIndex.removeFromIndex(oldPath)
|
||||||
await NotesIndex.addToIndexAndCache(file)
|
await NotesIndex.addToIndexAndMemCache(file)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -89,7 +89,7 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
|
|
||||||
onunload(): void {
|
onunload(): void {
|
||||||
console.log('Omnisearch - Interrupting PDF indexing')
|
console.log('Omnisearch - Interrupting PDF indexing')
|
||||||
NotesIndex.pdfQueue.clearQueue()
|
NotesIndex.processQueue.clearQueue()
|
||||||
}
|
}
|
||||||
|
|
||||||
addRibbonButton(): void {
|
addRibbonButton(): void {
|
||||||
|
|||||||
@@ -9,21 +9,26 @@ import {
|
|||||||
} from './utils'
|
} from './utils'
|
||||||
import { getNonExistingNotes, removeAnchors } from './notes'
|
import { getNonExistingNotes, removeAnchors } from './notes'
|
||||||
import { pdfManager } from './pdf-manager'
|
import { pdfManager } from './pdf-manager'
|
||||||
import type { IndexedDocument } from './globals'
|
|
||||||
import { settings } from './settings'
|
import { settings } from './settings'
|
||||||
import * as Search from './search'
|
import * as Search from './search'
|
||||||
// import PQueue from 'p-queue-compat'
|
// import PQueue from 'p-queue-compat'
|
||||||
import pLimit from 'p-limit'
|
|
||||||
import { cacheManager } from './cache-manager'
|
import { cacheManager } from './cache-manager'
|
||||||
|
import pLimit from 'p-limit'
|
||||||
|
import type { IndexedDocument } from './globals'
|
||||||
|
|
||||||
export const pdfQueue = pLimit(settings.backgroundProcesses)
|
/**
|
||||||
|
* Use this processing queue to handle all heavy work
|
||||||
|
*/
|
||||||
|
export const processQueue = pLimit(settings.backgroundProcesses)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a file to the search index
|
* Adds a file to the search index
|
||||||
* @param file
|
* @param file
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function addToIndexAndCache(file: TAbstractFile): Promise<void> {
|
export async function addToIndexAndMemCache(
|
||||||
|
file: TAbstractFile
|
||||||
|
): Promise<void> {
|
||||||
if (!(file instanceof TFile) || !isFileIndexable(file.path)) {
|
if (!(file instanceof TFile) || !isFileIndexable(file.path)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -154,7 +159,7 @@ export async function refreshIndex(): Promise<void> {
|
|||||||
}
|
}
|
||||||
for (const note of notesToReindex) {
|
for (const note of notesToReindex) {
|
||||||
removeFromIndex(note.path)
|
removeFromIndex(note.path)
|
||||||
await addToIndexAndCache(note)
|
await addToIndexAndMemCache(note)
|
||||||
await wait(0)
|
await wait(0)
|
||||||
}
|
}
|
||||||
notesToReindex.clear()
|
notesToReindex.clear()
|
||||||
@@ -173,8 +178,8 @@ export async function indexPDFs() {
|
|||||||
removeFromIndex(file.path)
|
removeFromIndex(file.path)
|
||||||
}
|
}
|
||||||
input.push(
|
input.push(
|
||||||
pdfQueue(async () => {
|
processQueue(async () => {
|
||||||
await addToIndexAndCache(file)
|
await addToIndexAndMemCache(file)
|
||||||
await cacheManager.writeMinisearchIndex(Search.minisearchInstance)
|
await cacheManager.writeMinisearchIndex(Search.minisearchInstance)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
import type { Query } from './query'
|
import type { Query } from './query'
|
||||||
import { settings } from './settings'
|
import { settings } from './settings'
|
||||||
import * as NotesIndex from './notes-index'
|
import * as NotesIndex from './notes-index'
|
||||||
import pLimit from 'p-limit'
|
|
||||||
import { cacheManager } from './cache-manager'
|
import { cacheManager } from './cache-manager'
|
||||||
|
|
||||||
export let minisearchInstance: MiniSearch<IndexedDocument>
|
export let minisearchInstance: MiniSearch<IndexedDocument>
|
||||||
@@ -98,13 +97,14 @@ export async function initGlobalSearchIndex(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read and index all the files into the search engine
|
// Read and index all the files into the search engine
|
||||||
const queue = pLimit(settings.backgroundProcesses)
|
|
||||||
const input = []
|
const input = []
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (cacheManager.getNoteFromMemCache(file.path)) {
|
if (cacheManager.getNoteFromMemCache(file.path)) {
|
||||||
NotesIndex.removeFromIndex(file.path)
|
NotesIndex.removeFromIndex(file.path)
|
||||||
}
|
}
|
||||||
input.push(queue(() => NotesIndex.addToIndexAndCache(file)))
|
input.push(
|
||||||
|
NotesIndex.processQueue(() => NotesIndex.addToIndexAndMemCache(file))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(input)
|
await Promise.all(input)
|
||||||
@@ -148,7 +148,7 @@ async function search(query: Query): Promise<SearchResult[]> {
|
|||||||
headings3: settings.weightH3,
|
headings3: settings.weightH3,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Downrank files that are in Obsidian's excluded list
|
// Downrank files that are in Obsidian's excluded list
|
||||||
if (settings.respectExcluded) {
|
if (settings.respectExcluded) {
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
@@ -218,9 +218,7 @@ export async function getSuggestions(
|
|||||||
options?: Partial<{ singleFilePath: string | null }>
|
options?: Partial<{ singleFilePath: string | null }>
|
||||||
): Promise<ResultNote[]> {
|
): Promise<ResultNote[]> {
|
||||||
// Get the raw results
|
// Get the raw results
|
||||||
console.time('search')
|
|
||||||
let results = await search(query)
|
let results = await search(query)
|
||||||
console.timeEnd('search')
|
|
||||||
if (!results.length) return []
|
if (!results.length) return []
|
||||||
|
|
||||||
// Extract tags from the query
|
// Extract tags from the query
|
||||||
|
|||||||
Reference in New Issue
Block a user