This is a live search application for electronic products using Elasticsearch and FastAPI. The application provides a powerful search interface that can handle natural language queries and return relevant results even with irrelevant keywords.
- Python 3.8 or higher
- Elasticsearch 8.x
- Docker (optional, for running Elasticsearch)
- Install the required dependencies:
pip install -r requirements.txt
-
Set up Elasticsearch:
- You can run Elasticsearch locally or use a cloud service
- For local development, you can use Docker:
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.11.0
-
Create a
.env
file with your Elasticsearch credentials (if needed):
ELASTICSEARCH_URL=http://localhost:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD=changeme
Start the FastAPI server:
python search_app.py
The server will start on http://localhost:8000
GET /search?query=your search query
Example:
GET /search?query=apple phone with good camera
The search is designed to handle natural language queries and will return relevant results even if the query contains irrelevant keywords.
- Fuzzy matching for typo tolerance
- Field boosting (name has highest priority, followed by description and features)
- Support for natural language queries
- Sample product data included for testing
- FastAPI for high-performance API endpoints
- Pydantic models for data validation
You can modify the search_app.py
file to:
- Add more product fields
- Change the search scoring
- Add more sample products
- Implement additional search features