Skip to content

Commit 06920d7

Browse files
devin-ai-integration[bot]aditya@dourolabs.xyz
authored andcommitted
fix(developer-hub): use exact/substring matching for multi-term search
The previous implementation used matchSorter for multi-term search which caused fuzzy matching to dominate results with the most common term. For multi-term search (comma/space separated), now uses: - Exact ID match for numeric terms (e.g., '925' matches pyth_lazer_id 925) - Case-insensitive substring match for text terms on symbol, name, description Single-term search still uses matchSorter for fuzzy ranking. Co-Authored-By: aditya@dourolabs.xyz <aditya@dourolabs.xyz>
1 parent 160d6a5 commit 06920d7

File tree

1 file changed

+30
-8
lines changed
  • apps/developer-hub/src/components/PriceFeedIdsProTable

1 file changed

+30
-8
lines changed

apps/developer-hub/src/components/PriceFeedIdsProTable/index.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,39 @@ export const PriceFeedIdsProTable = () => {
7979
});
8080
}
8181

82-
// For multiple terms, return items matching ANY term (OR logic)
83-
const matchedItems = new Set<(typeof items)[number]>();
82+
// For multiple terms, use exact/substring matching with OR logic
83+
// This ensures each term finds its specific matches
84+
const termMatchesItem = (
85+
item: (typeof items)[number],
86+
term: string,
87+
): boolean => {
88+
// Numeric ID match - exact match for numeric terms
89+
if (/^\d+$/.test(term)) {
90+
return String(item.pyth_lazer_id) === term;
91+
}
92+
93+
// String match - case-insensitive substring match
94+
const symbol = item.symbol.toLowerCase();
95+
const name = item.name.toLowerCase();
96+
const description = item.description.toLowerCase();
97+
98+
return (
99+
symbol.includes(term) ||
100+
name.includes(term) ||
101+
description.includes(term)
102+
);
103+
};
104+
105+
// Use Map to deduplicate by pyth_lazer_id
106+
const matchedItems = new Map<number, (typeof items)[number]>();
84107
for (const term of searchTerms) {
85-
const matches = matchSorter(items, term, {
86-
keys: ["pyth_lazer_id", "symbol", "name", "description"],
87-
});
88-
for (const match of matches) {
89-
matchedItems.add(match);
108+
for (const item of items) {
109+
if (termMatchesItem(item, term)) {
110+
matchedItems.set(item.pyth_lazer_id, item);
111+
}
90112
}
91113
}
92-
return [...matchedItems];
114+
return [...matchedItems.values()];
93115
},
94116
{
95117
defaultSort: "pyth_lazer_id",

0 commit comments

Comments
 (0)