test: simplify query expansion duplicate count · openclaw/openclaw@cac418d
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
File tree
packages/memory-host-sdk/src/host
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { expandQueryForFts, extractKeywords } from "./query-expansion.js"; |
3 | 3 | |
| 4 | +function countKeyword(keywords: readonly string[], keyword: string): number { |
| 5 | +let count = 0; |
| 6 | +for (const candidate of keywords) { |
| 7 | +if (candidate === keyword) { |
| 8 | +count++; |
| 9 | +} |
| 10 | +} |
| 11 | +return count; |
| 12 | +} |
| 13 | + |
4 | 14 | describe("extractKeywords", () => { |
5 | 15 | it("extracts keywords from English conversational query", () => { |
6 | 16 | const keywords = extractKeywords("that thing we discussed about the API"); |
@@ -171,8 +181,7 @@ describe("extractKeywords", () => {
|
171 | 181 | |
172 | 182 | it("removes duplicate keywords", () => { |
173 | 183 | const keywords = extractKeywords("test test testing"); |
174 | | -const testCount = keywords.filter((k) => k === "test").length; |
175 | | -expect(testCount).toBe(1); |
| 184 | +expect(countKeyword(keywords, "test")).toBe(1); |
176 | 185 | }); |
177 | 186 | |
178 | 187 | describe("with trigram tokenizer", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。