Prompt
Building search for a marketplace with filters and autocomplete
Latest observation
Here’s a solid blueprint for building search for a marketplace with filters and autocomplete.
1) Core requirements
A marketplace search usually needs:
- Keyword search over listings, titles, descriptions, brands, categories
- Faceted filters like:
- category
- price range
- location / shipping
- condition
- brand
- seller rating
- availability
- Sorts like:
- relevance
- newest
- price low/high
- popularity
- Autocomplete / typeahead
- query suggestions
- category suggestions
- recent/popular searches
- possibly item suggestions with thumbnails
- Good relevance
- typo tolerance
- synonym handling
- boosting by popularity, recency, conversion
- Fast response
- ideally <100–200ms from search backend
2) Recommended architecture
A common setup:
Frontend
- Search input with debounce
- Autocomplete dropdown
- Filter sidebar / chips
- Infinite scroll or paginated result list
Backend
- Search service API
- Indexing pipeline
- Analytics/events pipeline
- Optional recommendation/ranking service
Search engine
Use one of:
- Elasticsearch / OpenSearch — most common for marketplaces
- Algolia — fastest to implement, managed, great autocomplete
- Meilisearch — simpler, developer-friendly
- Solr — older but capable
If you need strong control and large scale, Elasticsearch/OpenSearch is usually the default.
3) Data model for search
Index each listing as a document.
Example fields:
{
"id": "123",
"title": "Apple iPhone 14 Pro Max 256GB",
"description": "Unlocked, great condition...",
"category": "phones",
"category_path": ["electronics", "phones", "smartphones"],
"brand": "Apple",
"price": 899.99,
"currency": "USD",
"condition": "used",
"location": {
"country": "US",
"region": "CA",
"city": "San Francisco"
},
"shipping": {
"pickup": true,
"delivery": true
},
"seller": {
"rating": 4.9,
"orders": 1342
},
"created_at": "2026-01-01T12:00:00Z",
"is_available": true,
"popularity_score": 87,
"search_text": "Apple iPhone 14 Pro Max 256GB Unlocked great condition"
}
Key point: store both:
- structured fields for filters/sorts
- full-text fields for keyword search
4) Search query flow
When user searches "iphone 14" with filters:
- Take text query
- Apply autocomplete suggestions as user types
- Execute search with filters
- Rank results by relevance + business signals
- Return:
- results
- facet counts
- paging info
- maybe “did you mean” suggestion
5) Filtering/facets
Build facets from indexed fields.
Typical facet types:
- Term facets: category, brand, condition, shipping type
- Range facets: price, rating
- Geo facets: distance / region
- Boolean facets: in stock, verified seller
Important:
- facet counts should update based on the current query + active filters
- if using Elasticsearch/OpenSearch, use aggregations
- for performance, keep facet fields keyword/numeric, not analyzed text
6) Autocomplete design
Autocomplete can include multiple suggestion types:
A. Query suggestions
User types: iph
Suggestions:
- iphone
- iphone 14
- iphone 14 pro
- iphone case
B. Category suggestions
- phones
- phone accessories
- refurbished phones
C. Product suggestions
- Apple iPhone 14 Pro Max
- iPhone 13 cases
D. Popular/recent searches
- trending searches
- user’s recent searches
Implementation options
- Prefix search on a dedicated suggest index
- Edge n-grams in Elasticsearch/OpenSearch
- Completion suggester
- Trie-based service for lightweight custom autocomplete
For marketplaces, often best to combine:
- query suggestions from logs/popularity
- product/title suggestions from index
- category suggestions from taxonomy
7) Relevance ranking
A marketplace rarely wants pure text matching only.
Useful scoring factors:
- text match quality
- exact title match boost
- category match boost
- brand match boost
- recency
- popularity / clicks / conversions
- seller quality
- availability
- location proximity
Example ranking strategy:
- base BM25 text relevance
- boost exact phrase in title
- boost listings with high conversion
- demote stale/unavailable items
8) Handling typos and synonyms
Very important for marketplace search.
Typo tolerance
- edit distance / fuzzy matching
- autocomplete should also tolerate simple misspellings
Synonyms
Examples:
- “tv” ↔ “television”
- “cellphone” ↔ “phone”
- “sneakers” ↔ “trainers” depending on region
Abbreviations
- “bnib” = brand new in box
- “w/” = with
- “rtx” = NVIDIA RTX
Maintain a synonym dictionary per locale/category.
9) Search UX best practices
- Debounce autocomplete requests: 100–200ms
- Show results while typing
- Allow filter chips at top
- Keep applied filters visible and removable
- Support “clear all”
- Preserve search state in URL query params
- Use skeleton loading, not empty flashes
- On mobile, keep filter UX simple and bottom-sheet based
10) API design
A simple API setup:
Search endpoint
GET /search?q=iphone&category=phones&min_price=500&max_price=1200&sort=relevance&page=1
Response:
{
"results": [...],
"facets": {
"brand": [{"key": "Apple", "count": 120}],
"condition": [{"key": "used", "count": 340}]
},
"total": 1243,
"page": 1,
"page_size": 24
}
Autocomplete endpoint
GET /autocomplete?q=iph
Response:
{
"suggestions": [
{"type": "query", "text": "iphone"},
{"type": "query", "text": "iphone 14"},
{"type": "category", "text": "smartphones"},
{"type": "product", "text": "Apple iPhone 14 Pro Max"}
]
}
11) Indexing pipeline
Whenever a listing is created/updated/deleted:
- Write to primary database
- Publish event to queue/stream
- Search indexer consumes event
- Update search index
- Optionally update autocomplete suggestion store
Use:
- Kafka / RabbitMQ / SQS / PubSub
- background workers for reindexing
12) Analytics loop
Track:
- search queries
- suggestion clicks
- result clicks
- conversions
- zero-result searches
- filter usage
- abandonment
Use this data to improve:
- query suggestions
- ranking
- synonyms
- spelling corrections
This is often where marketplaces get big gains.
13) Scaling considerations
For large catalogs:
- shard the search index
- cache popular queries
- precompute common facets if needed
- use separate indexes for:
- live listings
- archived listings
- suggestions
- tune analyzers for your language and category mix
For autocomplete:
- keep it fast and lightweight
- avoid heavyweight ranking on every keystroke
14) A practical implementation choice
If you want the fastest path:
Option A: Algolia
Best if you want:
- quick implementation
- excellent autocomplete
- managed scaling
- less infra complexity
Option B: Elasticsearch/OpenSearch
Best if you want:
- more control
- custom ranking
- lower vendor lock-in
- strong faceted search
Option C: Meilisearch
Best if you want:
- simpler setup
- good developer experience
- smaller-scale marketplace
15) Suggested MVP
Start with:
- text search over title + description
- filters: category, price, location, condition
- sort: relevance/newest/price
- autocomplete with query suggestions
- basic typo tolerance
- analytics on searches and clicks
Then iterate with:
- synonyms
- better ranking
- category-aware search
- personalized ranking
- trending queries
- search result merchandising
If you want, I can also give you:
- a concrete Elasticsearch/OpenSearch mapping and query example, or
- a full system design diagram for marketplace search + autocomplete.