Skip to content

Spotlight rank

Score every chunk in a compiled document against a probe.

import { Create, spotlight } from "@koda.oss/glyph";
const doc = spotlight.New(
"Goodbye moon under quiet stars. Unrelated pasta recipe.",
);
const results = doc.Rank(Create("Goodbye moon under quiet stars").glyph);
for (const hit of results) {
console.log(hit.score, hit.text);
}
interface GlyphSpotlightResult {
text: string;
glyph: Glyph;
length: number;
score: number;
comparison: GlyphComparisonResult;
matched?: string | number; // when probe is a group
}

Results are sorted by score descending. Every compiled chunk appears once (no threshold filter).

When the probe is a GlyphGroup, pairwise scores are aggregated with GroupResultAggregatorSum by default (sum of similarities). Pass aggregate to override (for example GroupResultAggregatorMax).

const texts = doc.Rank(probe, { textOutput: true });
// string[] — same order as full results