MCPcopy Create free account
hub / github.com/codeaashu/claude-code / query

Function query

web/lib/workers/search.worker.ts:81–115  ·  view source on GitHub ↗
(
  q: string,
  limit = 20
)

Source from the content-addressed store, hash-verified

79}
80
81function query(
82 q: string,
83 limit = 20
84): SearchResult[] {
85 const tokens = tokenize(q);
86 if (!tokens.length) return [];
87
88 // Score by how many query tokens appear
89 const scores = new Map<number, number>();
90 for (const token of tokens) {
91 for (const [term, set] of index) {
92 if (term.includes(token)) {
93 const boost = term === token ? 2 : 1; // exact > partial
94 for (const idx of set) {
95 scores.set(idx, (scores.get(idx) ?? 0) + boost);
96 }
97 }
98 }
99 }
100
101 return Array.from(scores.entries())
102 .sort((a, b) => b[1] - a[1])
103 .slice(0, limit)
104 .map(([idx, score]) => {
105 const entry = entries[idx];
106 return {
107 conversationId: entry.conversationId,
108 messageId: entry.messageId,
109 snippet: extractSnippet(entry.text, q),
110 score,
111 createdAt: entry.createdAt,
112 };
113 })
114 .filter((r) => r.conversationId !== "__removed__");
115}
116
117self.addEventListener("message", (e: MessageEvent<InMessage>) => {
118 const msg = e.data;

Callers 1

search.worker.tsFile · 0.70

Calls 5

entriesMethod · 0.80
tokenizeFunction · 0.70
extractSnippetFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected