Better searching
All checks were successful
Publish Library / Build NPM Project (push) Successful in 10s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2026-08-22 12:27:54 -04:00
parent c5207261fa
commit 86730f1de8
4 changed files with 46 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import {pipeline} from 'node:stream/promises';
import {Readable} from 'node:stream';
import {ZimReader} from './reader.js';
import {zimCatalog, zimCatalogInfo, CATALOG_URL} from './catalog.js';
import {fuzzyMatch, titleFromUrl} from './utils.js';
/** Manages a local directory of ZIM archives: listing, update checks, downloads, and reading. */
export class ZimManager {
@@ -146,7 +147,7 @@ export class ZimManager {
}
/** Fuzzy-searches titles across every local ZIM in the library, merging & re-ranking hits by score. */
async search(terms, {limit = 20, htmlOnly = true} = {}) {
async search(terms, {limit = 10, htmlOnly = true} = {}) {
const local = await this.list();
const perZim = await Promise.all(local.map(async ({file, meta}) => {
let reader;
@@ -160,6 +161,6 @@ export class ZimManager {
await reader?.close();
}
}));
return perZim.flat().toSorted((a, b) => b.score - a.score).slice(0, limit);
return perZim.flat().filter(a => a.score > 0).toSorted((a, b) => b.score - a.score).slice(0, limit);
}
}