← back to Rentv
server: fix broken facet counts in /api/unified-search (the /re-search admin search). The build+type filters ran BEFORE the facet-count computation, contradicting the code's own comment ('over the term/amount-filtered set, before build/type narrowing'). So selecting a build/type zeroed out the OTHER facet chips — you couldn't see counts for or switch to other builds/types. Moved the facet count above the build/type filters. Verified live: facets now stable across a build filter while results still narrow correctly
e8952c253bf09d743f772e33a40da49000d18d15 · 2026-08-06 02:53:46 -0700 · Steve
Files touched
Diff
commit e8952c253bf09d743f772e33a40da49000d18d15
Author: Steve <steve@designerwallcoverings.com>
Date: Thu Aug 6 02:53:46 2026 -0700
server: fix broken facet counts in /api/unified-search (the /re-search admin search). The build+type filters ran BEFORE the facet-count computation, contradicting the code's own comment ('over the term/amount-filtered set, before build/type narrowing'). So selecting a build/type zeroed out the OTHER facet chips — you couldn't see counts for or switch to other builds/types. Moved the facet count above the build/type filters. Verified live: facets now stable across a build filter while results still narrow correctly
---
server.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
index b51fa0b4..a9466432 100644
--- a/server.js
+++ b/server.js
@@ -354,8 +354,8 @@ app.get('/api/unified-search', adminOnly, (req, r) => {
const ql = String(req.query.q || '').trim().toLowerCase();
const terms = ql ? ql.split(/\s+/).filter(Boolean) : [];
let out = rows;
- if (build) out = out.filter((x) => x.build === build);
- if (type) out = out.filter((x) => x.type === type);
+ // Filters that must NOT reset the facet chips run first; the build/type chips are counted over THIS
+ // set (below) so they always show a count for every build/type — even when one is already selected.
if (year) out = out.filter((x) => String(x.date || '').startsWith(String(year)));
if (min) out = out.filter((x) => (x.amount || 0) >= min);
if (max) out = out.filter((x) => (x.amount || 0) <= max);
@@ -363,6 +363,9 @@ app.get('/api/unified-search', adminOnly, (req, r) => {
// facet counts (over the term/amount-filtered set, before build/type narrowing) for the UI chips
const byBuild = {}, byType = {};
for (const x of out) { byBuild[x.build] = (byBuild[x.build] || 0) + 1; byType[x.type] = (byType[x.type] || 0) + 1; }
+ // NOW narrow to the selected build/type for the actual result rows (facets already counted above)
+ if (build) out = out.filter((x) => x.build === build);
+ if (type) out = out.filter((x) => x.type === type);
// rank: title hit > recency > amount
const titleHit = (x) => terms.length && terms.every((w) => (x.title || '').toLowerCase().includes(w)) ? 1 : 0;
out = out.slice().sort((a, b) => titleHit(b) - titleHit(a) || String(b.date || '').localeCompare(String(a.date || '')) || (b.amount || 0) - (a.amount || 0));
← ff82d81d auto-save: 2026-08-06T02:47:50 (7 files) — data/deals-regist
·
back to Rentv
·
server: Cody gate — proper DRILL-DOWN faceting in /api/unifi e9b3e49f →