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

Function prepareQuery

packages/text-search/src/matcher.ts:103–125  ·  view source on GitHub ↗

* Prepare a query for matching.

(query: string, options: MatcherOptions)

Source from the content-addressed store, hash-verified

101 * Prepare a query for matching.
102 */
103function prepareQuery(query: string, options: MatcherOptions): PreparedQuery {
104 const opts: Required<MatcherOptions> = {
105 stem: options.stem ?? true,
106 removeStopwords: options.removeStopwords ?? true,
107 minLength: options.minLength ?? 1,
108 k1: options.k1 ?? 1.2,
109 b: options.b ?? 0.75,
110 exactMatchBonus: options.exactMatchBonus ?? 0.15,
111 prefixMatchBonus: options.prefixMatchBonus ?? 0.1,
112 consecutiveBonus: options.consecutiveBonus ?? 0.1,
113 positionWeight: options.positionWeight ?? 0.05,
114 };
115
116 const tokens = tokenize(query, opts);
117 const termSet = new Set(tokens.map((t) => t.stemmed));
118
119 return {
120 original: query.toLowerCase(),
121 tokens,
122 termSet,
123 options: opts,
124 };
125}
126
127/**
128 * Calculate BM25-style score for term matching.

Callers 2

createMatcherFunction · 0.85
createDetailedMatcherFunction · 0.85

Calls 2

tokenizeFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected