Introduction
Solr powers production search for major platforms. This article explores real-world use cases with practical implementation patterns.
E-commerce Search
Product Catalog
// Products schema
{
"fields": [
{"name": "id", "type": "string"},
{"name": "name", "type": "text_en"},
{"name": "description", "type": "text_en"},
{"name": "category", "type": "string"},
{"name": "brand", "type": "string"},
{"name": "price", "type": "pfloat"},
{"name": "in_stock", "type": "boolean"},
{"name": "rating", "type": "pfloat"}
]
}
Search Features
# Autocomplete
curl "http://localhost:8983/solr/products/suggest?q=wire&suggest=true"
# Faceted search
curl "http://localhost:8983/solr/products/select?q=*:*&facet=true&facet.field=category&facet.field=brand"
# Range filtering
curl "http://localhost:8983/solr/products/select?q=*:*&fq=price:[20 TO 100]"
Enterprise Search
Document Search
// Documents schema
{
"fields": [
{"name": "id", "type": "string"},
{"name": "title", "type": "text_en"},
{"name": "content", "type": "text_en"},
{"name": "author", "type": "string"},
{"name": "date", "type": "pdate"},
{"name": "type", "type": "string"}
]
}
Access Control
# Filter by user permissions
curl "http://localhost:8983/solr/docs/select?q=*:*&fq=allowed_users:user123"
Site Search
Web Site Search
// Pages schema
{
"fields": [
{"name": "url", "type": "string"},
{"name": "title", "type": "text_en"},
{"name": "body", "type": "text_en"},
{"name": "meta_description", "type": "text_en"},
{"name": "keywords", "type": "text_en"}
]
}
SEO Features
# Highlighting
curl "http://localhost:8983/solr/pages/select?q=search&hl=true&hl.field=body"
# Snippets
curl "http://localhost:8983/solr/pages/select?q=search&hl=true&hl.snippets=3"
Best Practices
Index Design
// Use copy fields for search
{
"copyFields": [
{"source": "title", "dest": "search_text"},
{"source": "description", "dest": "search_text"},
{"source": "keywords", "dest": "search_text"}
]
}
Query Optimization
# Use filter queries for facets
curl "http://localhost:8983/solr/products/select?q=*:*&fq=category:Electronics"
# Return only needed fields
curl "http://localhost:8983/solr/products/select?q=wire&fl=id,name,price"
Conclusion
Solr excels in production environments requiring powerful search. From e-commerce to enterprise search, Solr delivers reliable, scalable search capabilities.
With proper schema design and query optimization, Solr can handle massive search workloads while providing relevant results.
Comments