diff --git a/index.html b/index.html
index af8fcf5..8d0e4bd 100644
--- a/index.html
+++ b/index.html
@@ -3826,7 +3826,7 @@
Suggest an entry
'compliance-governance': { c:'#D97706', b:'#FFFBEB', cb:'rgba(217,119,6,0.28)' },
};
- const active = { cat: '', license: '', lang: '', judgement: '', search: '', pypi: false, hf: false };
+ const active = { cat: '', license: '', licenseRaw: '', lang: '', judgement: '', search: '', pypi: false, hf: false };
function getVisible() {
return rows.filter(r => {
@@ -3834,6 +3834,8 @@ Suggest an entry
const catOk = !active.cat || d.cat === active.cat;
// License now filters by bucket (data-license-bucket) rather than raw string.
const licOk = !active.license || d.licenseBucket === active.license;
+ // A search for a specific licence (e.g. "MIT") filters by the raw SPDX id.
+ const licRawOk = !active.licenseRaw || (d.license || '').toLowerCase() === active.licenseRaw;
const langOk = !active.lang || d.lang === active.lang;
// Judgement: '__none__' matches not-scored (empty data-judgement).
const judgeOk = !active.judgement
@@ -3843,7 +3845,7 @@ Suggest an entry
const nameEl = r.querySelector('.entry-name');
const name = nameEl ? nameEl.textContent.toLowerCase() : '';
const searchOk = !active.search || name.includes(active.search);
- return catOk && licOk && langOk && judgeOk && pypiOk && hfOk && searchOk;
+ return catOk && licOk && licRawOk && langOk && judgeOk && pypiOk && hfOk && searchOk;
});
}
@@ -3962,6 +3964,17 @@ Suggest an entry
bar.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
active[activeKey] = btn.dataset.value || '';
+ // A filter click leaves search mode: release anything a keyword search set
+ // (a language or raw licence) so this filter isn't AND-ed with a stuck one.
+ if (active._searchSetLang) {
+ active._searchSetLang = false;
+ if (activeKey !== 'lang') { active.lang = ''; const ls = document.getElementById('filter-lang'); if (ls) ls.value = ''; }
+ }
+ if (active._searchSetLic) {
+ active._searchSetLic = false;
+ if (activeKey !== 'licenseRaw') active.licenseRaw = '';
+ }
+ const si = document.getElementById('entry-search'); if (si) { si.value = ''; active.search = ''; }
applyFilters();
});
}
@@ -4079,6 +4092,12 @@ Suggest an entry
const langSel = document.getElementById('filter-lang');
if (langSel) langSel.value = '';
}
+ // Same for a LICENCE filter applied by a keyword search (e.g. "MIT"):
+ // editing the box releases it so clearing returns to the full catalogue.
+ if (active._searchSetLic) {
+ active.licenseRaw = '';
+ active._searchSetLic = false;
+ }
currentPage = 1;
renderPage();
});
@@ -4104,6 +4123,23 @@ Suggest an entry
rows.forEach(r => { if ((r.dataset.lang || '').toLowerCase() === lowerName) v = r.dataset.lang; });
return v;
},
+ // Lowercased raw licence ids present in the catalogue (e.g. "mit", "apache-2.0").
+ knownLicenses: () => {
+ const s = new Set();
+ rows.forEach(r => { const l = (r.dataset.license || '').trim().toLowerCase(); if (l) s.add(l); });
+ return s;
+ },
+ // Map a user's licence keyword to the raw id the cards carry. Handles common
+ // short forms ("apache" -> the "apache-2.0" present), else an exact id match.
+ licenseValue: (kw) => {
+ const k = kw.toLowerCase();
+ const known = new Set();
+ rows.forEach(r => { const l = (r.dataset.license || '').toLowerCase(); if (l) known.add(l); });
+ if (known.has(k)) return k; // exact id, e.g. "mit"
+ // short form → first id that starts with it, e.g. "apache" → "apache-2.0"
+ for (const id of known) { if (id.startsWith(k + '-') || id === k) return id; }
+ return '';
+ },
};
})();
@@ -4174,7 +4210,10 @@ Suggest an entry
function tryKeywordRoute(q) {
const F = window.MACHFilters;
if (!F) return false; // filters not ready → fall through
- const words = q.toLowerCase().split(/\s+/).filter(Boolean);
+ let words = q.toLowerCase().split(/\s+/).filter(Boolean);
+ // Allow a trailing "license"/"licence" word: "MIT license" → "mit", so a
+ // natural licence query still routes locally (the reported bug was 0 results).
+ if (words.length === 2 && /^licen[cs]e$/.test(words[1])) words = [words[0]];
if (words.length !== 1) return false; // only single-token queries route locally
const w = words[0];
@@ -4198,6 +4237,26 @@ Suggest an entry
});
return true;
}
+
+ // 2) exact licence match → filter by the raw SPDX id (e.g. "MIT" → all MIT
+ // entries). Fixes "MIT"/"MIT license" returning ~0 via the semantic API.
+ const licVal = F.licenseValue(w); // '' if not a known licence
+ if (licVal) {
+ semanticOn = false;
+ F.active.search = '';
+ F.active.licenseRaw = licVal; // filter by raw id
+ F.active._searchSetLic = true; // clear it when the box is edited
+ F.applyFilters();
+
+ const n = F.getVisible().length;
+ status.hidden = false;
+ status.innerHTML = `Showing all ${esc(licVal.toUpperCase())} entries (${n}) — filtered by licence. Clear`;
+ document.getElementById('sem-clear').addEventListener('click', () => {
+ F.active.licenseRaw = ''; input.value = ''; F.active.search = '';
+ F.applyFilters(); status.hidden = true;
+ });
+ return true;
+ }
return false;
}
diff --git a/tests/search.spec.js b/tests/search.spec.js
index b801b2a..b2cadd9 100644
--- a/tests/search.spec.js
+++ b/tests/search.spec.js
@@ -91,6 +91,42 @@ test('clicking a category filter after a search resets the view (not stuck/blank
expect(offCategory).toBe(0);
});
+test('typing a licence ("MIT") filters to MIT entries, not ~0', async ({ page }) => {
+ // Ground truth: how many MIT-licensed entries exist (from the DOM)?
+ const mitTotal = await page.$$eval(CARD, (cards) =>
+ cards.filter((c) => c.getAttribute('data-license') === 'MIT').length
+ );
+ expect(mitTotal).toBeGreaterThan(40); // the catalogue really has many MIT entries
+
+ await page.fill(SEARCH, 'MIT');
+ await page.click(RUN);
+
+ // The licence route must MATCH all MIT entries via the LOCAL filter — the bug
+ // routed "MIT" to the semantic API, which returned ~0. We check the matched
+ // set (across pages), not just the visible page.
+ await expect.poll(() => matchedCount(page)).toBeGreaterThan(mitTotal - 5);
+ await expect.poll(() => visibleCount(page)).toBeGreaterThan(0);
+
+ // Every matched card is actually MIT-licensed (the filter applied correctly).
+ const offLicence = await page.evaluate(() =>
+ window.MACHFilters.getVisible().filter(
+ (c) => c.getAttribute('data-license') !== 'MIT'
+ ).length
+ );
+ expect(offLicence).toBe(0);
+});
+
+test('a two-word licence query ("MIT license") also routes to the local filter', async ({ page }) => {
+ const mitTotal = await page.$$eval(CARD, (cards) =>
+ cards.filter((c) => c.getAttribute('data-license') === 'MIT').length
+ );
+ await page.fill(SEARCH, 'MIT license');
+ await page.click(RUN);
+ // "MIT license" (two words) must still route locally, not fall through to the
+ // semantic API — the exact reported bug ("MIT license" -> 0 results).
+ await expect.poll(() => matchedCount(page)).toBeGreaterThan(mitTotal - 5);
+});
+
test('clearing the search returns to the full catalogue', async ({ page }) => {
const allMatched = await matchedCount(page); // every entry, unfiltered
await page.fill(SEARCH, 'python');