← back to Linenwallpaper
/api/facets drill-down: count each dimension over the active filtered set (q/aesthetic/vendor) via shared filterProducts(); /api/products reuses helper
a31c934492563c0a98f2a338bcc9d6937717ca0a · 2026-06-01 07:33:58 -0700 · Steve
Files touched
Diff
commit a31c934492563c0a98f2a338bcc9d6937717ca0a
Author: Steve <steve@designerwallcoverings.com>
Date: Mon Jun 1 07:33:58 2026 -0700
/api/facets drill-down: count each dimension over the active filtered set (q/aesthetic/vendor) via shared filterProducts(); /api/products reuses helper
---
server.js | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/server.js b/server.js
index a1b59d9..d3e8955 100644
--- a/server.js
+++ b/server.js
@@ -152,15 +152,22 @@ require('./_universal-auth')(app, { siteName: "linenwallpaper" });
app.use(express.static(path.join(__dirname, 'public')));
-app.get('/api/products', (req, res) => {
- const { q, aesthetic, vendor, page = 1, limit = 24, sort = 'newest'} = req.query;
+// Shared filter so /api/products and /api/facets agree on the active result set.
+// Pass `skip` to omit one dimension (drill-down facet counts count over the OTHER active facets).
+function filterProducts({ q, aesthetic, vendor }, skip) {
let list = PRODUCTS_NICHE;
- if (q) {
- const needle = q.toLowerCase();
+ if (skip !== 'q' && q) {
+ const needle = String(q).toLowerCase();
list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
}
- if (aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
- if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ if (skip !== 'aesthetic' && aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+ if (skip !== 'vendor' && vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ return list;
+}
+
+app.get('/api/products', (req, res) => {
+ const { q, aesthetic, vendor, page = 1, limit = 24, sort = 'newest'} = req.query;
+ let list = filterProducts({ q, aesthetic, vendor });
list = sortProducts(list, sort);
const total = list.length;
const pageNum = Math.max(1, parseInt(page) || 1);
@@ -179,12 +186,16 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ const { q, aesthetic, vendor } = req.query;
const aesthetics = {}; const vendors = {};
- for (const p of PRODUCTS_NICHE) {
+ // Each dimension counts over the set filtered by the OTHER active facets (drill-down).
+ for (const p of filterProducts({ q, aesthetic, vendor }, 'aesthetic')) {
aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
+ }
+ for (const p of filterProducts({ q, aesthetic, vendor }, 'vendor')) {
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
+ res.json({ aesthetics, vendors, total: filterProducts({ q, aesthetic, vendor }).length });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));
← 8c441a9 noopener,noreferrer on sister-site window.open popup
·
back to Linenwallpaper
·
301 redirect legacy /(history|vocabulary|sourcing|care|trade b3f1755 →