Fixed #79
This commit is contained in:
@@ -28,8 +28,8 @@ $: if (searchQuery) {
|
|||||||
resultNotes = []
|
resultNotes = []
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
reindexNotes()
|
await reindexNotes()
|
||||||
searchQuery = lastSearch
|
searchQuery = lastSearch
|
||||||
eventBus.enable("vault")
|
eventBus.enable("vault")
|
||||||
eventBus.on("vault", "enter", openNoteAndCloseModal)
|
eventBus.on("vault", "enter", openNoteAndCloseModal)
|
||||||
@@ -47,7 +47,7 @@ onDestroy(() => {
|
|||||||
|
|
||||||
async function updateResults() {
|
async function updateResults() {
|
||||||
query = new Query(searchQuery)
|
query = new Query(searchQuery)
|
||||||
resultNotes = await getSuggestions(query)
|
resultNotes = (await getSuggestions(query)).sort((a, b) => b.score - a.score)
|
||||||
lastSearch = searchQuery
|
lastSearch = searchQuery
|
||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
scrollIntoView()
|
scrollIntoView()
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ $: title = settings.showShortName ? note.basename : note.path
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
{#if matches.length > 0}
|
{#if matches.length > 0}
|
||||||
<span class="omnisearch-result__counter">
|
<span class="omnisearch-result__counter">
|
||||||
{matches.length} {matches.length > 1 ? "matches" : "match"}
|
{matches.length} {matches.length > 1 ? "matches" : "match"}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="omnisearch-result__body">
|
<div class="omnisearch-result__body">
|
||||||
|
|||||||
@@ -227,6 +227,11 @@ export async function getSuggestions(
|
|||||||
let results = await search(query)
|
let results = await search(query)
|
||||||
if (!results.length) return []
|
if (!results.length) return []
|
||||||
|
|
||||||
|
// Extract tags from the query
|
||||||
|
const tags = query.segments
|
||||||
|
.filter(s => s.value.startsWith('#'))
|
||||||
|
.map(s => s.value)
|
||||||
|
|
||||||
// Either keep the 50 first results,
|
// Either keep the 50 first results,
|
||||||
// or the one corresponding to `singleFile`
|
// or the one corresponding to `singleFile`
|
||||||
if (options?.singleFilePath) {
|
if (options?.singleFilePath) {
|
||||||
@@ -238,12 +243,9 @@ export async function getSuggestions(
|
|||||||
results = results.slice(0, 50)
|
results = results.slice(0, 50)
|
||||||
|
|
||||||
// Put the results with tags on top
|
// Put the results with tags on top
|
||||||
const tags = query.segments
|
|
||||||
.filter(s => s.value.startsWith('#'))
|
|
||||||
.map(s => s.value)
|
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
if (result.tags.includes(tag)) {
|
if ((result.tags ?? []).includes(tag)) {
|
||||||
result.score *= 100
|
result.score *= 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,6 +270,7 @@ export async function getSuggestions(
|
|||||||
query.segments.some(s => w.startsWith(s.value)),
|
query.segments.some(s => w.startsWith(s.value)),
|
||||||
),
|
),
|
||||||
...query.segments.filter(s => s.exact).map(s => s.value),
|
...query.segments.filter(s => s.exact).map(s => s.value),
|
||||||
|
...tags,
|
||||||
]
|
]
|
||||||
|
|
||||||
const matches = getMatches(note.content, stringsToRegex(foundWords))
|
const matches = getMatches(note.content, stringsToRegex(foundWords))
|
||||||
|
|||||||
Reference in New Issue
Block a user