We built DEV3 AI Product Filter & Smart Search as a WooCommerce plugin in PHP with a React admin and a small storefront script. The filter engine never queries product meta at request time: it reads precomputed lists and does set maths in memory.
Key design decisions
- A facet index table. Each product is flattened into rows of
(product_id, facet, value, num_value): categories with their ancestors, attributes, every in-stock variation price, rating, stock, sale and chosen meta or ACF fields. Saves, stock changes, reviews and term edits queue a re-index at shutdown, and Action Scheduler rebuilds it nightly.
- Cached postings lists. For each facet the index is turned into value → packed product IDs and stored once per index version. A filter request decodes those lists and intersects them; no per-request scans of the index table.
- Disjunctive counts. The count next to each colour ignores the colour selection but respects every other filter, so shoppers can always see how many products a second colour would add.
- Stock-aware variations. A variable hoodie only appears under the sizes that are in stock, and its price range uses the in-stock variation prices.
- SEO-safe URLs. Filter states map to pretty paths such as
/shop/filter/color/black/ with one canonical URL per state. Combinations are noindex unless the merchant turns one into a landing page with its own title, meta description, H1 and intro, listed in the XML sitemap.
- Natural language without AI first. A rules parser maps queries to filters using the store's own vocabulary and synonyms. When the Google Gemini API is connected, its interpretation is validated against the catalogue before use, and a failure falls back to the parser.
Architecture
Filters render as a horizontal bar, a sidebar or a mobile drawer, in block themes and classic themes, through a block, widget, shortcode, Elementor widget or WPBakery element. The storefront calls a same-origin, rate-limited REST endpoint that returns results, counts, the price range and rating counts in one response, and the main shop query is narrowed with the same ID set. Optional AI features (semantic search with embeddings stored in the database, "Build my filters", synonym and typo lists, zero-result fixes and landing-page copy) all produce drafts the merchant accepts or rejects. The API client, encrypted key storage, job runner and usage logs come from a shared core used across DEV3's plugins.