Project-Stage-Academy / UA1244_beta

1 stars 0 forks source link

First part:Integrate Elasticsearch for Fast Search Access to Startups and Projects #125

Closed Chelakhovl closed 2 weeks ago

Chelakhovl commented 2 weeks ago

Integrate Elasticsearch for Enhanced Search Functionality on Startups and Projects - Part 1

Objective: This pull request is part one of a task aimed at integrating Elasticsearch into the project to enhance the search capabilities for the Startup and Project models. By leveraging Elasticsearch, the application can support efficient, fast, and complex search queries, including keyword search, filtering, and sorting functionalities.

Tasks Completed:

Setup and Installation

Installed Elasticsearch and configured a local instance. Installed django-elasticsearch-dsl and django-elasticsearch-dsl-drf libraries to bridge Django with Elasticsearch. Define Elasticsearch Settings

Added necessary settings to settings.py for connecting Django to the local Elasticsearch instance. Create Elasticsearch Documents

Defined Elasticsearch document mappings for Startup and Project models. This includes creating documents.py in the respective apps: Mapped fields for StartupDocument (e.g., company_name, funding_stage, location). Mapped fields for ProjectDocument (e.g., title, status, required_amount). Data Synchronization

Ran a management command to index existing data, allowing current database entries to be searchable in Elasticsearch. Added Django signals to keep Elasticsearch indexes synchronized with database changes (create, update, delete) on Startup and Project records. Build DRF Views for Search

Implemented search views leveraging django-elasticsearch-dsl-drf, allowing users to perform searches on both Startup and Project models. Configured complex filtering and sorting capabilities in these views. Create Document Serializers

Added serializers for StartupDocument and ProjectDocument to convert Elasticsearch data to JSON format, making it consumable by API clients. URL Routing for Search Endpoints

Set up URL patterns for the search endpoints. Now, users can access: startups/search/ to search for startups. projects/search/ to search for projects. Summary of Improvements: This integration lays the groundwork for faster and more versatile search capabilities in the application. By indexing data in Elasticsearch and providing endpoints for searching, the application can now handle complex search requirements more efficiently. 2 1 3 5 4