#134 - Async loading of minisearch cache

Using a custom build of minisearch
This commit is contained in:
Simon Cambier
2024-05-23 21:38:46 +02:00
parent dcfb77f551
commit 5f5417f0ff
5 changed files with 2662 additions and 3184 deletions

View File

@@ -57,6 +57,14 @@ build({
to: ['./'], to: ['./'],
}, },
}), }),
{
name: 'resolve-minisearch',
setup(build) {
build.onResolve({ filter: /^minisearch$/ }, () => {
return { path: path.resolve('node_modules/minisearch/src/MiniSearch.ts') };
});
},
},
], ],
format: 'cjs', format: 'cjs',
watch: !prod, watch: !prod,

View File

@@ -44,7 +44,7 @@
"dexie": "^3.2.7", "dexie": "^3.2.7",
"lodash-es": "4.17.21", "lodash-es": "4.17.21",
"markdown-link-extractor": "^4.0.2", "markdown-link-extractor": "^4.0.2",
"minisearch": "^6.3.0", "minisearch": "github:scambier/minisearch#async-load-json",
"pure-md5": "^0.1.14", "pure-md5": "^0.1.14",
"search-query-parser": "^1.6.0" "search-query-parser": "^1.6.0"
}, },

5647
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -59,6 +59,7 @@ export class Omnisearch {
} }
}, },
} }
private minisearch: MiniSearch private minisearch: MiniSearch
/** Map<path, mtime> */ /** Map<path, mtime> */
private indexedDocuments: Map<string, number> = new Map() private indexedDocuments: Map<string, number> = new Map()
@@ -75,8 +76,7 @@ export class Omnisearch {
async loadCache(): Promise<boolean> { async loadCache(): Promise<boolean> {
const cache = await cacheManager.getMinisearchCache() const cache = await cacheManager.getMinisearchCache()
if (cache) { if (cache) {
// console.log('Omnisearch - Cache', cache) this.minisearch = await MiniSearch.loadJSAsync(cache.data, Omnisearch.options)
this.minisearch = MiniSearch.loadJS(cache.data, Omnisearch.options)
this.indexedDocuments = new Map(cache.paths.map(o => [o.path, o.mtime])) this.indexedDocuments = new Map(cache.paths.map(o => [o.path, o.mtime]))
return true return true
} }

View File

@@ -19,7 +19,10 @@
"lib": [ "lib": [
"DOM", "DOM",
"ES2021" "ES2021"
] ],
"paths": {
"minisearch": ["node_modules/minisearch/src/MiniSearch.ts"]
}
}, },
"include": [ "include": [
"**/*.ts", "**/*.ts",