Skip to main content
This recipe demonstrates building a product catalog search with filtering, sorting, typo tolerance, and relevance boosting.

Schema Design

The schema balances searchability with filtering and sorting capabilities:

Sample Data

Waiting for Indexing

Index updates are batched for performance, so newly added data may not appear in search results immediately. Use SEARCH.WAITINDEXING to ensure all pending updates are processed before querying:
This is especially useful in scripts or tests where you need to query immediately after inserting data. In production, the slight indexing delay is usually acceptable and calling this after every write is not recommended. The simplest search uses smart matching for natural language queries:
Smart matching automatically handles this by:
  1. Prioritizing exact phrase matches (“wireless headphones” adjacent)
  2. Including documents with both terms in any order
  3. Finding fuzzy matches for typos

Search with Typo Tolerance

Users often misspell product names. Use fuzzy matching to handle typos:
Combine text search with filters for category, price, and availability:

Boosting Premium Results

Promote featured products or preferred brands using score boosting:

Sorting and Pagination

Sort results by price or rating, with pagination for large result sets:

New Arrivals

Find recently added products using date range queries:

Excluding Out-of-Stock Items

Use $mustNot to filter out unavailable products:
Search across multiple categories using $in:

Counting Results

Use SEARCH.COUNT to get the number of matching documents without retrieving them. This is useful for pagination UI (“Showing 1-20 of 156 results”) or analytics:

Key Takeaways

  • Use NOTOKENIZE for categories and codes that should match exactly
  • Use NOSTEM for brand names to prevent unwanted stemming
  • Mark price, rating, and date fields as FAST for sorting
  • Combine $must, $should, and $mustNot for complex filtering
  • Use $boost to promote featured or preferred items
  • Use SEARCH.COUNT to get result counts for pagination UI
  • Smart matching handles most natural language queries automatically