mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-04 05:47:59 +01:00
* feat(search): match with @bitbaum/searchkit; forgive a slip in every search box
Site search was the one box in the fleet with typo tolerance, and it carried
its own copies of what searchkit now does once for everyone: folding, an
edit distance, the typo budget, prefix lookup, highlight offsets and snippet
cutting. Those now come from the package. What stays is what is genuinely
this corpus's: the TF-IDF ranking over long documents with type weights and
phrase bonuses (search/score.ts), the narrow plural rule, the stop words, and
"a real word is never corrected".
A full swap to createSearch's tie-break ranking was tried against the golden
pairs and lost two: "gallium ch" put Chalco first (a two-letter prefix that
covers a one-word title outranks an exact rare word) and "quartz" put a
company above the quartz bottleneck (no term frequency). So searchkit decides
which words a typed word could mean (candidates) and where to mark them;
the ranking stays here.
Small gains in the engine: a slip in the word still being typed ("photres")
and in a word the corpus has only as the start of others ("canno" -> Canon)
now find it; marks use original offsets, so accented words are marked where
they stand. Real words are still never corrected, so result counts for them
are unchanged.
The other boxes had no tolerance at all and now share the package: the globe's
country finder and the palette's page list (search + marks), and the filter
boxes on Exposure, Data series and the desk (lib/text-filter.ts: membership
only, every word required, the table's own order kept). One slip in a country
or page name used to return nothing 96-97% of the time; success@1 is now
0.989 for both. Careers keeps its SQL substring, with a comment saying why.
Tests: generated typo suites (typoCases + evaluate) over company and country
names in site search, every country name in the finder, and every page label
in the palette, plus hand-picked slips and the existing golden pairs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf
* chore(deps): add @bitbaum/searchkit, pinned to orangecat a868c0a9
The fleet's one search package, installed from orangecat by commit
(packages/searchkit). It ships compiled dist/, so no transpile step.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf
* docs(changelog): link the search entry to #179
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf
---------
Co-authored-by: Claude <noreply@anthropic.com>
25 lines
835 B
TypeScript
25 lines
835 B
TypeScript
/**
|
|
* A table's filter-by-typing box: the rows the typed words find, a slip
|
|
* forgiven ("wolfsped" is still Wolfspeed), leaving the table's own order —
|
|
* a sort the reader chose, newest first — alone. Matching is
|
|
* `@bitbaum/searchkit`'s, the same rules as the site search and ⌘K.
|
|
*
|
|
* A filter narrows: every typed word must match (no word is set aside, as the
|
|
* search box does), so a second word never quietly widens the table.
|
|
*/
|
|
import { createSearch, type SearchSpec } from '@bitbaum/searchkit';
|
|
|
|
export function textFilter<T>(
|
|
rows: readonly T[],
|
|
spec: SearchSpec<T>,
|
|
query: string,
|
|
): (row: T) => boolean {
|
|
if (!query.trim()) return () => true;
|
|
const found = new Set(
|
|
createSearch(rows, spec)
|
|
.search(query, { relax: false })
|
|
.map((h) => h.item),
|
|
);
|
|
return (row) => found.has(row);
|
|
}
|