Storefront Faceted Filtering
Typesense-backed faceted filters on collection pages. Auto-detected from product data with merchant-configurable overrides — no theme code required for the defaults.
Overview
Faceted filtering is built into every Cartly collection page and powered by Typesense. Filters appear automatically based on your product catalog — no theme changes required. Merchants can then reorder, relabel, or hide filters from Admin → Settings → Storefront Filters.
Built-in filter types
| Filter | URL param prefix | Notes |
|---|---|---|
| Variant option (Color, Size, …) | filter.v.option.<key> | Auto-detected from product variants. The key is the option name as stored (any language, spaces allowed); matched case-insensitively. |
| Product tag | filter.p.tag | Several values match any of them (OR). |
| Vendor | filter.p.vendor | The product’s Vendor field. Has no values (skip the group) when no product has a vendor. |
| Availability | filter.v.availability | 1 (or true) = in-stock only. Rendered from filter.true_value, not values. |
| Price range | filter.v.price.gte / .lte | URL values in major units of the shop currency, with its own decimals (19.99 USD, 1000 JPY, 12.500 KWD). In Liquid, range_min_major/range_max_major and min_value.major/max_value.major are in those same units; range_min/range_max/min_value.value/max_value.value are minor units (for | money). Swap is silently corrected. |
| Product metafield | filter.p.m.<ns>.<key> (variant: filter.v.m.<ns>.<key>) | Requires storefront_filterable=true on the definition. |
URL Parameters
Filters are fully URL-driven. Each filter.* parameter is parsed by the backend URL parser and translated into a Typesense filter_by expression (every value is matched literally). The url_to_add / url_to_remove helpers keep the other filters and the sort and return to page 1; collection.paginate URLs keep the filters and sort.
# Base collection URL with filters applied
/collections/t-shirts
?filter.v.option.color=Red # variant option filter (option name as in the catalog,
# any language, spaces encoded: filter.v.option.Frame+finish=Walnut)
&filter.v.option.size=M
&filter.p.tag=new # product tag filter
&filter.p.tag=sale # several values of one filter match ANY of them (OR);
# different filters combine with AND
&filter.p.vendor=Nike # vendor (the product's Vendor field)
&filter.v.availability=1 # in-stock only (1 / true)
&filter.v.price.gte=20 # price range — major units of the shop currency
&filter.v.price.lte=100 # (its own decimals: 19.99 USD, 1000 JPY, 12.500 KWD)
&filter.p.m.custom.brand=Nike # product metafield filter (filter.v.m.… = variant metafield)
&sort_by=price-ascending # sort (kept when a filter changes)
&page=2 # pagination (a filter change goes back to page 1)
# /collections/all is a first-class virtual collection (all products in the shop)Sort values
| sort_by value | Typesense sort |
|---|---|
manual (default, “Featured”) | relevance, then most recently updated |
price-ascending | min_price ASC |
price-descending | min_price DESC |
title-ascending | title ASC |
title-descending | title DESC |
created-descending / newest | created_at DESC |
created-ascending | created_at ASC |
best-selling | created_at DESC (no sales data in the index yet) |
Liquid Globals
On collection pages the storefront renderer injects these globals in addition to the standard collection object:
collection.filters— array ofLiquidFilterobjects, already merged with admin overrides and sorted byposition.collection.current_tags—[]stringof active tag filter values (mirrors Shopify's global for theme compat).collection.products_count— integer count of products after filtering (from Typesensefound).collection.paginate—pages,current_page,previous/next(url,title) andparts; every URL keeps the active filters and sort, so never hand-build?page=Nlinks.collection.sort_by/collection.sort_options— the active sort and the list of{value, name}options.
{%- comment -%}
collection.filters — LiquidFilter objects, merged with admin overrides and
already in display order. Link every option with its own url_to_add /
url_to_remove; never build filter URLs by hand.
{%- endcomment -%}
{%- for filter in collection.filters -%}
{%- comment -%}Skip a group with nothing to pick (e.g. a shop with no vendors).{%- endcomment -%}
{%- unless filter.type == 'range' -%}
{%- if filter.true_value == blank and filter.values.size == 0 -%}{%- continue -%}{%- endif -%}
{%- endunless -%}
<div class="filter-group">
<h3>{{ filter.label | escape }}</h3>
{%- if filter.type == 'range' -%}
{%- comment -%}
Price: the URL takes major units of the shop currency (its own decimals).
Show the *_major fields; range_min / range_max / *.value are minor units
(pass those to | money).
{%- endcomment -%}
<form method="get" action="{{ collection.url }}">
{%- comment -%}Re-submit every OTHER active facet + sort, or Apply wipes them.{%- endcomment -%}
{%- for af in collection.filters -%}
{%- unless af.param_name == filter.param_name -%}
{%- for av in af.active_values -%}<input type="hidden" name="{{ af.param_name | escape }}" value="{{ av.value | escape }}">{%- endfor -%}
{%- if af.type == 'boolean' and af.true_value.active -%}<input type="hidden" name="{{ af.param_name | escape }}" value="{{ af.true_value.value | escape }}">{%- endif -%}
{%- endunless -%}
{%- endfor -%}
{%- if collection.sort_by != blank and collection.sort_by != 'manual' -%}<input type="hidden" name="sort_by" value="{{ collection.sort_by | escape }}">{%- endif -%}
<input type="number" step="any" name="{{ filter.param_name }}.gte"
min="{{ filter.range_min_major }}" placeholder="{{ filter.range_min | money }}"
value="{% if filter.min_value.value %}{{ filter.min_value.major }}{% endif %}">
<input type="number" step="any" name="{{ filter.param_name }}.lte"
max="{{ filter.range_max_major }}" placeholder="{{ filter.range_max | money }}"
value="{% if filter.max_value.value %}{{ filter.max_value.major }}{% endif %}">
<button type="submit">Apply</button>
</form>
{%- elsif filter.type == 'boolean' and filter.true_value != blank -%}
{%- comment -%}In-stock toggle: values is empty, the option is true_value.{%- endcomment -%}
{%- assign tv = filter.true_value -%}
<a href="{% if tv.active %}{{ tv.url_to_remove }}{% else %}{{ tv.url_to_add }}{% endif %}"
class="filter-chip{% if tv.active %} active{% endif %}">{{ tv.label | escape }} ({{ tv.count }})</a>
{%- else -%}
{%- comment -%}list / swatch — and a boolean METAFIELD facet, whose true/false buckets are values.{%- endcomment -%}
{%- for value in filter.values -%}
<a href="{% if value.active %}{{ value.url_to_remove }}{% else %}{{ value.url_to_add }}{% endif %}"
class="filter-chip{% if value.active %} active{% endif %}">{{ value.label | escape }} ({{ value.count }})</a>
{%- endfor -%}
{%- endif -%}
</div>
{%- endfor -%}
{%- comment -%} Other collection fields used with filters {%- endcomment -%}
{{ collection.products_count }} {%- comment -%} count after filtering {%- endcomment -%}
{{ collection.current_tags }} {%- comment -%} active tag values — Shopify compat {%- endcomment -%}
{{ collection.sort_by }} {%- comment -%} active sort; options in collection.sort_options {%- endcomment -%}
{{ collection.paginate.next.url }} {%- comment -%} page links keep every active filter + sort {%- endcomment -%}LiquidFilter fields
| Field | Type | Description |
|---|---|---|
label | string | Display label — admin override or auto-humanized |
param_name | string | URL key, e.g. filter.v.option.Color, filter.p.vendor, filter.v.price |
type | string | list | swatch | range | boolean |
values | array | Option objects (see below) for list / swatch and for a boolean metafield facet; empty for range and the in-stock toggle |
active_values | array | The values selected in the current URL (also when they match no product now) |
true_value | object | In-stock toggle (filter.v.availability) only: label, value, count, active, url_to_add / url_to_remove |
range_min / range_max | integer | range only — lowest / highest price among the facet buckets Typesense returned for the current result set (up to 100 distinct prices), in minor units of the shop currency (what | money takes) |
range_min_major / range_max_major | number | range only — the same bounds in major units of the shop currency, with its own decimals (4.2 USD, 1000 JPY) — the units of the URL and of a price input |
min_value / max_value | object | range only, absent when that bound is not applied — .value = the applied bound in minor units, .major = the same in major units (what the URL takes: <param_name>.gte / .lte) |
Filter value fields
| Field | Description |
|---|---|
label | Display string (e.g. "Red") |
value | The value as it appears in the URL |
count | Product count from Typesense facet_counts |
active | Whether this value is in the current URL |
url_to_add | Current URL + this filter value applied (set when inactive; page reset, sort kept) |
url_to_remove | Current URL with this filter value removed (set when active) |
API Reference
All endpoints are under /admin/storefront-filters and require a valid admin JWT. State-changing endpoints require an X-Idempotency-Key header.
# List overrides for a shop
GET /admin/storefront-filters
Authorization: Bearer <admin-jwt>
# Create an override (customize a built-in or metafield filter)
POST /admin/storefront-filters
X-Idempotency-Key: <uuid>
{
"source_type": "OPTION", # TAG | VENDOR | AVAILABILITY | PRICE | OPTION | METAFIELD
"source_key": "color", # option name (OPTION) or namespace.key (METAFIELD); empty for built-ins
"label_override": "Colour", # optional
"display_type_override": "swatch", # optional: list | swatch | range | boolean
"scope": "GLOBAL", # GLOBAL, or COLLECTION + "collection_ids": ["<uuid>", …]
"position": 1,
"hidden": false
}
# Reorder overrides
POST /admin/storefront-filters/reorder
{ "positions": [{ "id": "<uuid>", "position": 1 }, ...] }
# Trigger a full-shop reindex (writes progress to import_job row)
POST /admin/storefront-filters/reindex
X-Idempotency-Key: <uuid>
# Poll reindex progress
GET /admin/storefront-filters/reindex-status
# Available filter sources (built-ins + detected option keys + filterable metafields)
GET /admin/storefront-filters/available-sources
# Detected variant option keys for the shop
GET /admin/products/option-keys| Method | Path | Description |
|---|---|---|
| GET | /admin/storefront-filters | List overrides (ordered by position) |
| GET | /admin/storefront-filters/available-sources | All filter sources: built-ins + options + filterable metafields |
| GET | /admin/products/option-keys | Detected variant option keys for the shop |
| POST | /admin/storefront-filters | Create override |
| PUT | /admin/storefront-filters/:id | Update override |
| DELETE | /admin/storefront-filters/:id | Delete override |
| POST | /admin/storefront-filters/reorder | Bulk reorder (max 200 positions) |
| POST | /admin/storefront-filters/reindex | Trigger full-shop Typesense reindex |
| GET | /admin/storefront-filters/reindex-status | Poll reindex progress (import_job row) |
Custom Filters (Metafields)
To add a filter for a custom product attribute (e.g. Brand, Material, Width) follow a two-step flow:
- Create a MetafieldDefinition with
storefront_filterable: true. Allowed field types:single_line_text,number_integer,number_decimal,boolean,color,metaobject_reference,list.single_line_text. The backend auto-triggers a Typesense schema update (ReindexShopWorkflow) to add the new field. - Assign values per product via the Metafields section on the product edit page or via the API. Each save emits an outbox event that reindexes the product in Typesense. Once indexed, the filter bucket appears in the storefront sidebar automatically.
Optionally create a StorefrontFilter override from Settings → Storefront Filters → + Add filter to customize the label, display type, position, or scope (GLOBAL vs. per-collection). Without an override, the filter uses auto-defaults.
# Step 1 — create a MetafieldDefinition with storefront_filterable = true
POST /admin/metafields/definitions
X-Idempotency-Key: <uuid>
{
"name": "Brand",
"namespace": "custom",
"key": "brand",
"field_type": "single_line_text", # allowed: single_line_text | number_integer |
# number_decimal | boolean | color |
# metaobject_reference | list.single_line_text
"owner_type": "product",
"storefront_filterable": true,
"filter_label": "Brand", # optional — falls back to name
"filter_display_type": "list" # optional: list | swatch | range | boolean (empty = list)
}
# Backend auto-triggers ReindexShopWorkflow to extend the Typesense schema.
# Step 2 — assign values per product (outbox → search-sync reindexes the product)
POST /admin/metafields
{ "owner_type": "product", "owner_id": "<product-uuid>",
"namespace": "custom", "key": "brand", "value": "Nike" }
# The filter appears automatically in /collections/* once Typesense has indexed
# at least one product with this metafield value.
# URL param format: ?filter.p.m.custom.brand=NikeReindex
The Typesense index is kept in sync via outbox events for individual products. A full shop reindex is needed when:
- A new
storefront_filterableMetafieldDefinition is created (auto-triggered) - New Typesense ProductDocument fields are added in a platform update
- Index drift is suspected (use the
velocity-cli catalog diffcommand)
Trigger via POST /admin/storefront-filters/reindex (UI button available in Settings → Storefront Filters). Progress is written to an import_job row and exposed via the reindex-status endpoint — the admin UI shows a progress bar.
On production, adding a new Typesense schema field also requires rebuilding and running the cartly-reindex-products binary manually (it is not rebuilt by the auto-deploy script):
cd /var/www/cartly/backend
/usr/local/go/bin/go build -o /opt/cartly/cartly-reindex-products ./cmd/reindex-products
set -a && source /var/www/cartly/backend/.env && set +a
/opt/cartly/cartly-reindex-products --shop=allDoS Guard
A per-shop Redis sliding-window guard limits cache amplification. Each unique (shop, collection-path) pair is tracked per minute using a Redis SADD+SCARD set. When the cardinality exceeds the threshold, a 5-minute pause sentinel is set and subsequent Typesense calls on that path are skipped — returning the unfiltered product list. This prevents a crawler from generating thousands of unique filter-param combinations and saturating the Typesense cluster.
The guard affects only the server-side Typesense fetch. The storefront page itself continues to render with unfiltered products while the sentinel is active.