query.ts
This file
Path
examples/burrow/packages/search/src/query.ts
29 lines · 783 bytes · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–29why, one step back1import { API, legacyFetch } from "@burrow/kit";2import type { Transport } from "@burrow/kit";34/** A search result: what matched, and how well. */5export interface Hit {6 readonly id: string;7 readonly score: number;8}910// The query run last, for "search again".11let lastQuery = "";1213/** Searches the index; the best hit comes first. */14export const search = async (15 query: string,16 transport?: Transport17): Promise<readonly Hit[]> => {18 lastQuery = query;1920 const hits: readonly Hit[] = JSON.parse(21 await legacyFetch(`${API}/search?q=${encodeURIComponent(query)}`, transport)22 );2324 return hits.toSorted((one, other) => other.score - one.score);25};2627/** Runs the last query again. */28export const searchAgain = (transport?: Transport) =>29 search(lastQuery, transport);