Skip to main content
This recipe demonstrates building a full-text blog search with highlighted snippets, phrase matching, and date filtering.

Schema Design

The schema prioritizes full-text search capabilities with date-based filtering:

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:
Smart matching handles natural language queries across title and body:

Search with Highlighted Results

Highlighting shows users why each result matched their query:

Custom Highlight Tags

Use custom tags for different rendering contexts:
Find articles containing exact phrases using double quotes or the $phrase operator:

Filter by Author

Find all articles by a specific author:

Date Range Queries

Find articles published within a specific time period:
Sort by view count to find popular content:

Boosting Title Matches

Prioritize matches in the title over body text:

Key Takeaways

  • Hash storage works well for flat document structures like blog articles
  • Use highlighting to show users why results matched their query
  • Boost title matches over body text for better relevance
  • Use $phrase with slop for flexible phrase matching
  • Combine date ranges with text search for temporal filtering
  • Mark viewCount as FAST to enable popularity sorting
  • Filter drafts using published: true in $must conditions