This commit is contained in:
Andrew Pimenov 2026-09-04 10:13:51 +03:00 • committed by GitHub
commit 34cac462ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,12 +44,8 @@ export function parseResultQuery(
return { op: m[1], threshold: v };
}
export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
const q = query.trim();
if (!q) return [];
const docs = deps.docs();
const rq = parseResultQuery(deps.engine, q);
if (rq && rq.threshold.kind === "quantity") {
function searchNumeric(deps: SearchDeps, docs: SearchDoc[], rq: { op: string; threshold: Value }): SearchHit[] {
if (rq.threshold.kind !== "quantity") return [];
const th = rq.threshold.value;
const hits: SearchHit[] = [];
for (const doc of docs) {
@ -95,6 +91,8 @@ export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
}
return hits;
}
function searchText(docs: SearchDoc[], q: string): SearchHit[] {
const ql = q.toLowerCase();
const hits: SearchHit[] = [];
for (const doc of docs) {
@ -114,6 +112,17 @@ export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
return hits;
}
export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
const q = query.trim();
if (!q) return [];
const docs = deps.docs();
const rq = parseResultQuery(deps.engine, q);
if (rq && rq.threshold.kind === "quantity") {
return searchNumeric(deps, docs, rq);
}
return searchText(docs, q);
}
export function initSearch(deps: SearchDeps): SearchController {
const overlay = $("#search-overlay");
const input = $<HTMLInputElement>("#search-input");