Bugfix/281 backticks (#282)

* #281 - Added backticks as a separation character

* #281 - Fixed case sensitive duplicates

* Fixed highlighting bug, and improved perfs

Also added logs
This commit is contained in:
Simon Cambier
2023-08-30 19:09:15 +02:00
committed by GitHub
parent b6c80e15ec
commit 92bef7daec
4 changed files with 19 additions and 27 deletions

View File

@@ -188,6 +188,7 @@ export class Omnisearch {
return []
}
logDebug('=== New search ===')
logDebug('Starting search for', query)
let fuzziness: number
@@ -299,6 +300,9 @@ export class Omnisearch {
// Sort results and keep the 50 best
results = results.sort((a, b) => b.score - a.score).slice(0, 50)
if (results.length)
logDebug('First result:', results[0])
const documents = await Promise.all(
results.map(async result => await cacheManager.getDocument(result.id))
)
@@ -306,7 +310,7 @@ export class Omnisearch {
// If the search query contains quotes, filter out results that don't have the exact match
const exactTerms = query.getExactTerms()
if (exactTerms.length) {
logDebug('Filtering with quoted terms')
logDebug('Filtering with quoted terms: ', exactTerms)
results = results.filter(r => {
const document = documents.find(d => d.path === r.id)
const title = document?.path.toLowerCase() ?? ''
@@ -353,8 +357,9 @@ export class Omnisearch {
warnDebug('Stopped getMatches at', count, 'results')
break
}
const m = match[2]
if (m) matches.push({ match: m, offset: match.index + 1 })
logDebug('match :', match)
const m = match[1]
if (m) matches.push({ match: m, offset: match.index })
}
// If the query can be found "as is" in the text, put this match first

View File

@@ -77,10 +77,12 @@ export class Query {
public getExactTerms(): string[] {
return [
...new Set([
...this.query.text.filter(o => o.split(' ').length > 1),
...this.#inQuotes,
]),
...new Set(
[
...this.query.text.filter(o => o.split(' ').length > 1),
...this.#inQuotes,
].map(str => str.toLowerCase())
),
]
}
}