evipedia-mcp-dev 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,11 +48,18 @@ async function searchReviews(query, limit = 20) {
|
|
|
48
48
|
fetchCached(`${BASE_URL}/reviews.json`)
|
|
49
49
|
]);
|
|
50
50
|
const bySlug = new Map(reviewsIndex.map((r) => [toSlug(r.permalink).toLowerCase(), r]));
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
51
|
+
const STOPWORDS = /* @__PURE__ */ new Set(["for", "the", "a", "an", "and", "or", "of", "to", "in", "on", "with", "vs", "versus"]);
|
|
52
|
+
const tokens = Array.from(new Set(
|
|
53
|
+
query.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length > 1 && !STOPWORDS.has(t))
|
|
54
|
+
));
|
|
55
|
+
if (tokens.length === 0) return [];
|
|
56
|
+
const scored = searchIndex.map((e) => {
|
|
57
|
+
const hay = [e.short_topic, e.alternate_names, e.ep_keywords, e.ep_category].map((v) => (v ?? "").toLowerCase()).join(" ");
|
|
58
|
+
return { e, score: tokens.reduce((n, t) => n + (hay.includes(t) ? 1 : 0), 0) };
|
|
59
|
+
});
|
|
60
|
+
const best = scored.reduce((m, s) => Math.max(m, s.score), 0);
|
|
61
|
+
if (best === 0) return [];
|
|
62
|
+
const matches = scored.filter((s) => s.score === best).map((s) => s.e);
|
|
56
63
|
return matches.slice(0, limit).map((e) => {
|
|
57
64
|
const r = bySlug.get(toSlug(e.url).toLowerCase());
|
|
58
65
|
return r ? { name: r.canonical_name, url: r.permalink, conclusion: r.er_conclusion, category: r.category } : { name: e.short_topic, url: e.url, category: e.ep_category };
|