generated from ztimson/template
Better searching
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user