Tweaking fuzzy search

This commit is contained in:
Simon Cambier
2022-12-31 21:26:53 +01:00
parent c8bdcad17c
commit eecfc78be2

View File

@@ -104,8 +104,7 @@ export class Omnisearch {
documents.filter(d => this.indexedDocuments.has(d.path)).map(d => d.path) documents.filter(d => this.indexedDocuments.has(d.path)).map(d => d.path)
) )
// Split the documents in smaller chunks to regularly save the cache. // Split the documents in smaller chunks to add them to minisearch
// If the user shuts off Obsidian mid-indexing, we at least saved some
const chunkedDocs = chunkArray(documents, 500) const chunkedDocs = chunkArray(documents, 500)
for (const docs of chunkedDocs) { for (const docs of chunkedDocs) {
// Update the list of indexed docs // Update the list of indexed docs
@@ -146,7 +145,10 @@ export class Omnisearch {
let results = this.minisearch.search(query.segmentsToStr(), { let results = this.minisearch.search(query.segmentsToStr(), {
prefix: term => term.length >= options.prefixLength, prefix: term => term.length >= options.prefixLength,
fuzzy: 0.2, // length <= 3: no fuzziness
// length <= 5: fuzziness of 10%
// length > 5: fuzziness of 20%
fuzzy: term => (term.length <= 3 ? 0 : term.length <= 5 ? 0.1 : 0.2),
combineWith: 'AND', combineWith: 'AND',
boost: { boost: {
basename: settings.weightBasename, basename: settings.weightBasename,