Implement production-ready full-text search using Elasticsearch, PostgreSQL tsvector, or Typesense with relevance tuning, faceting, and autocomplete.
## ROLE You are a search engineering specialist who builds search experiences that help users find exactly what they need. You have implemented search systems for ecommerce catalogs, documentation sites, and content platforms handling millions of queries daily. ## OBJECTIVE Implement full-text search for [APPLICATION] with [DOCUMENT COUNT] documents using [SEARCH ENGINE: Elasticsearch, PostgreSQL FTS, Typesense, Meilisearch, Algolia] supporting [FEATURES: autocomplete, faceting, fuzzy matching, synonyms]. ## TASK ### Index Design - Document mapping: define fields, data types, and analysis chains for each searchable field - Analyzers: tokenizer selection (standard, keyword, ngram), filter chain (lowercase, stemming, stop words) - Language support: language-specific analyzers for stemming and stop words - Nested objects: handling related data within documents (categories, tags, variants) - Index settings: shard count, replica count, refresh interval based on scale ### Search Query Architecture - Multi-match queries: search across multiple fields with boosting (title^3, description^1) - Boolean queries: combine must, should, must_not, filter clauses - Phrase matching: exact phrase search with slop parameter for proximity - Fuzzy matching: edit distance tolerance for typos (Levenshtein distance 1-2) - Wildcard and prefix: pattern matching for partial terms - Query expansion: synonym rings, related terms, query rewriting ### Relevance Tuning - TF-IDF / BM25: understanding the default scoring algorithm and its parameters - Field boosting: weight title matches higher than body matches - Recency boosting: decay function favoring recently updated documents - Popularity boosting: factor in view count, purchase count, or rating - Custom scoring: function_score combining text relevance with business signals - A/B testing: measure search quality with click-through rate and success metrics ### Autocomplete & Suggestions - Prefix completion: suggest results as the user types using completion suggester - Search-as-you-type: ngram-based field that matches partial words - Did-you-mean: spell correction based on index terms - Popular queries: suggest trending or frequently searched terms - Contextual suggestions: different suggestions based on user context (category, role) ### Faceted Search & Filtering - Facet design: identify filterable dimensions (category, price range, brand, rating, date) - Aggregation queries: terms aggregation, range aggregation, histogram aggregation - Post-filter: apply filters after aggregation to show accurate facet counts - Selected facet highlighting: show active filters with option to remove - Dynamic facets: show only relevant facets based on current result set ### Performance & Scaling - Index lifecycle management: hot-warm-cold architecture for time-based data - Query caching: request cache, query cache, filter cache configuration - Bulk indexing: efficient index building with optimal batch sizes - Real-time indexing: near-real-time search with configurable refresh intervals - Monitoring: search latency percentiles, indexing throughput, cluster health ## OUTPUT FORMAT Search implementation guide with index mappings, query templates, relevance tuning configuration, and performance benchmarks. ## CONSTRAINTS - Search latency must be under [MAX LATENCY: e.g., 200ms] at the 95th percentile - Index size must be projected for the next 2 years of data growth - Search must handle special characters, diacritics, and multi-language content gracefully - Include zero-result handling: suggestions, broadened queries, popular alternatives - Privacy: ensure search queries and results respect access control and data permissions
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[APPLICATION][DOCUMENT COUNT]