Faceted Search
Faceted search lets users narrow down results by selecting filter values. dcupl provides facets() to get available options with counts and addCondition() to filter results.
Key dcupl Functions
| Function | Purpose |
|---|---|
catalog.fn.facets() |
Get filter options with counts for an attribute |
query.addCondition() |
Add filter condition |
query.setCondition() |
Replace all conditions |
query.clear() |
Remove all active filters |
Getting Facets
Use facets() to get available filter values with their counts.
const list = dcupl.lists.create({ modelKey: 'Product' });
const categoryFacets = list.catalog.fn.facets({
attribute: 'category'
});
// Returns: [{ key: 'electronics', value: 'Electronics', count: 42, enabled: true }, ...]Facets automatically update based on current filters - counts reflect only matching items.
Applying Filters
Use addCondition() to filter results based on user selections.
// Single filter
list.catalog.query.addCondition({
operator: 'eq',
attribute: 'category',
value: 'Electronics'
});
const results = list.catalog.query.items();Multi-Select Filters (OR Logic)
Allow selecting multiple values within the same attribute.
// User selects "Electronics" OR "Clothing" categories
list.catalog.query.addCondition({
groupKey: 'category_filter',
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'category', value: 'Electronics' },
{ operator: 'eq', attribute: 'category', value: 'Clothing' }
]
});Combining Filters (AND Logic)
Filters across different attributes combine with AND logic.
// Category filter (OR within)
list.catalog.query.addCondition({
groupKey: 'category_filter',
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'category', value: 'Electronics' }
]
});
// Brand filter (OR within) - ANDed with category
list.catalog.query.addCondition({
groupKey: 'brand_filter',
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'brand', value: 'Apple' },
{ operator: 'eq', attribute: 'brand', value: 'Samsung' }
]
});
// Results: Electronics items that are Apple OR SamsungComplete Flow
const list = dcupl.lists.create({ modelKey: 'Product' });
// 1. Get initial facets
let categories = list.catalog.fn.facets({ attribute: 'category' });
let brands = list.catalog.fn.facets({ attribute: 'brand' });
// 2. User selects "Electronics"
list.catalog.query.addCondition({
groupKey: 'category_filter',
groupType: 'or',
queries: [{ operator: 'eq', attribute: 'category', value: 'Electronics' }]
});
// 3. Facets automatically update - brand counts now reflect only Electronics
brands = list.catalog.fn.facets({ attribute: 'brand' });
// 4. Get filtered results
const results = list.catalog.query.items();
// 5. Clear all filters
list.catalog.query.clear();Related
- Facets Function - Complete facets() API reference
- Query Filter - Filter operators and syntax
- Query Logic - AND/OR grouping details