Did a bit of cleaning
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { get } from 'svelte/store'
|
|
||||||
import type { TFile } from 'obsidian'
|
|
||||||
import CmpInput from './CmpInput.svelte'
|
import CmpInput from './CmpInput.svelte'
|
||||||
import CmpNoteResult from './CmpNoteResult.svelte'
|
import CmpNoteResult from './CmpNoteResult.svelte'
|
||||||
import type { ResultNote } from './globals'
|
import type { ResultNote } from './globals'
|
||||||
@@ -11,15 +9,14 @@ import { escapeHTML, escapeRegex, getAllIndexes, highlighter } from './utils'
|
|||||||
export let plugin: OmnisearchPlugin
|
export let plugin: OmnisearchPlugin
|
||||||
|
|
||||||
searchQuery.subscribe(q => {
|
searchQuery.subscribe(q => {
|
||||||
getSuggestions(q).then(results => {
|
const results = getSuggestions(q)
|
||||||
resultNotes.set(results)
|
resultNotes.set(results)
|
||||||
if (results.length) {
|
if (results.length) {
|
||||||
selectedNoteId.set(results[0].path)
|
selectedNoteId.set(results[0].path)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
async function getSuggestions(query: string): Promise<ResultNote[]> {
|
function getSuggestions(query: string): ResultNote[] {
|
||||||
const results = plugin.minisearch
|
const results = plugin.minisearch
|
||||||
.search(query, {
|
.search(query, {
|
||||||
prefix: true,
|
prefix: true,
|
||||||
@@ -37,14 +34,11 @@ async function getSuggestions(query: string): Promise<ResultNote[]> {
|
|||||||
// console.log(`Omnisearch - Results for "${query}"`)
|
// console.log(`Omnisearch - Results for "${query}"`)
|
||||||
// console.log(results)
|
// console.log(results)
|
||||||
|
|
||||||
const suggestions = await Promise.all(
|
const suggestions =
|
||||||
results.map(async result => {
|
results.map(result => {
|
||||||
const file = plugin.app.vault.getAbstractFileByPath(result.id) as TFile
|
let note = plugin.indexedNotes[result.id]
|
||||||
// const metadata = this.app.metadataCache.getFileCache(file)
|
let basename = escapeHTML(note.basename)
|
||||||
let content = escapeHTML(
|
let content = escapeHTML(note.content)
|
||||||
await plugin.app.vault.cachedRead(file),
|
|
||||||
).toLowerCase()
|
|
||||||
let basename = file.basename
|
|
||||||
|
|
||||||
// Sort the terms from smaller to larger
|
// Sort the terms from smaller to larger
|
||||||
// and highlight them in the title and body
|
// and highlight them in the title and body
|
||||||
@@ -72,13 +66,14 @@ async function getSuggestions(query: string): Promise<ResultNote[]> {
|
|||||||
const resultNote: ResultNote = {
|
const resultNote: ResultNote = {
|
||||||
content,
|
content,
|
||||||
basename,
|
basename,
|
||||||
path: file.path,
|
path: note.path,
|
||||||
matches,
|
matches,
|
||||||
occurence: 0,
|
occurence: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultNote
|
return resultNote
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
|
|
||||||
return suggestions
|
return suggestions
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user