MCPcopy Create free account
hub / github.com/codemix/graph / searchTermPrefix

Method searchTermPrefix

packages/graph/src/indexes/FullTextIndex.ts:224–252  ·  view source on GitHub ↗

* Find documents where any indexed term starts with the given prefix. * This is more efficient than searchPrefix for word-based prefix search. * * @param termPrefix The term prefix to search for. * @returns Set of element IDs with terms starting with the prefix.

(termPrefix: string)

Source from the content-addressed store, hash-verified

222 * @returns Set of element IDs with terms starting with the prefix.
223 */
224 public searchTermPrefix(termPrefix: string): Set<ElementId> {
225 const result = new Set<ElementId>();
226
227 if (!termPrefix || termPrefix.length === 0) {
228 return result;
229 }
230
231 // Normalize and stem the prefix
232 const normalizedPrefixes = extractTerms(termPrefix, {
233 ...this.#options,
234 stem: false, // Don't stem for prefix matching
235 });
236
237 if (normalizedPrefixes.length === 0) {
238 return result;
239 }
240
241 const prefix = normalizedPrefixes[0]!;
242
243 for (const [term, ids] of this.#invertedIndex) {
244 if (term.startsWith(prefix)) {
245 for (const id of ids) {
246 result.add(id);
247 }
248 }
249 }
250
251 return result;
252 }
253
254 /**
255 * Get the document IDs that contain ALL of the given terms (AND semantics).

Callers 1

#performIndexLookupMethod · 0.80

Calls 3

extractTermsFunction · 0.90
addMethod · 0.65
startsWithMethod · 0.45

Tested by

no test coverage detected