Elffuss BraidHub

kikocis/continue public

Merge pull request #6410 from continuedev/nate/improve-history-search-algorithm

Improve history search with multi-stage matching algorithm
Changesetc2565dc2794520169e16d11e84ee9926a2acc1eaa8fd9dc0cd9bfac24f9b0ef9
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-03 19:04 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-03 19:04 -07:00
Parents1c73a1f84d7c, d94819353983

Browse the files at this changeset

1 file changed

modified gui/src/components/History/index.tsx +35 −4
@@ -76,10 +76,41 @@
7676 const platform = useMemo(() => getPlatform(), []);
7777
7878 const filteredAndSortedSessions: SessionMetadata[] = useMemo(() => {
79- const sessionIds = minisearch
80- .search(searchTerm, {
81- fuzzy: 0.1,
82- })
79+ // 1. Exact phrase matching
80+ const exactResults = minisearch.search(searchTerm, {
81+ fuzzy: false,
82+ });
83+
84+ // 2. Fuzzy matching with higher tolerance
85+ const fuzzyResults = minisearch.search(searchTerm, {
86+ fuzzy: 0.3,
87+ });
88+
89+ // 3. Prefix matching for partial words
90+ const prefixResults = minisearch.search(searchTerm, {
91+ prefix: true,
92+ fuzzy: 0.2,
93+ });
94+
95+ // Combine results, with exact matches having higher priority
96+ const allResults = [
97+ ...exactResults.map((r) => ({ ...r, priority: 3 })),
98+ ...fuzzyResults.map((r) => ({ ...r, priority: 2 })),
99+ ...prefixResults.map((r) => ({ ...r, priority: 1 })),
100+ ];
101+
102+ // Remove duplicates while preserving highest priority
103+ const uniqueResultsMap = new Map<string, any>();
104+ allResults.forEach((result) => {
105+ const existing = uniqueResultsMap.get(result.id);
106+ if (!existing || existing.priority < result.priority) {
107+ uniqueResultsMap.set(result.id, result);
108+ }
109+ });
110+ const uniqueResults = Array.from(uniqueResultsMap.values());
111+
112+ const sessionIds = uniqueResults
113+ .sort((a, b) => b.priority - a.priority || b.score - a.score)
83114 .map((result) => result.id);
84115
85116 return allSessionMetadata