Skip to content

Commit fb75ff8

Browse files
andy5995claude
andauthored
Support multi-keyword (AND) search in both search inputs (#150)
Previously, both the home-page JSON search and the in-page table filter treated the entire input as a single substring: "video player" only matched rows where those two words appeared adjacent in that order. Multi-word queries the user might actually type — "python ide", "video editor", "image viewer" — would miss obvious matches. Whitespace-split the query into terms and require every term to be present somewhere in the haystack. AND semantics, no order required. Empty query still matches everything (terms.every of [] is vacuously true, matching the previous q === '' branch). The table-filter visible-count message already showed "(X of N shown)", so no copy changes are needed; the count keeps making sense. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7e32ae0 commit fb75ff8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

assets/js/search.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939

4040
function update() {
4141
var q = input.value.trim().toLowerCase();
42+
// Whitespace-separated terms, ANDed. Empty query matches every row.
43+
var terms = q.split(/\s+/).filter(Boolean);
4244
var visible = 0;
4345
for (var i = 0; i < rows.length; i++) {
44-
var match = q === '' || haystacks[i].indexOf(q) !== -1;
46+
var hay = haystacks[i];
47+
var match = terms.every(function (t) { return hay.indexOf(t) !== -1; });
4548
rows[i].style.display = match ? '' : 'none';
4649
if (match) visible++;
4750
}
@@ -96,12 +99,13 @@
9699
status.textContent = apps.length + ' apps in the database.';
97100
return;
98101
}
99-
var needle = q.toLowerCase();
102+
// Whitespace-separated terms, ANDed against name + description.
103+
var terms = q.toLowerCase().split(/\s+/).filter(Boolean);
100104
var matches = [];
101105
for (var i = 0; i < apps.length; i++) {
102106
var a = apps[i];
103107
var hay = (a.packageName + ' ' + (a.description || '')).toLowerCase();
104-
if (hay.indexOf(needle) !== -1) matches.push(a);
108+
if (terms.every(function (t) { return hay.indexOf(t) !== -1; })) matches.push(a);
105109
}
106110
if (!matches.length) {
107111
status.textContent = 'No apps match "' + q + '".';

0 commit comments

Comments
 (0)