An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
Auto Index and Search Django Model Instances with RediSearch (using redis-search-django)
Overview of My Submission
I built an Installable Django Package called redis-search-django
as a part of Redis Hackathon on DEV. redis-search-django
is a Django package that provides auto indexing and searching capabilities for Django Model instances using RediSearch.
redis-search-django
internally uses redis-om-python and redis-py
redis-search-django
is Available on Python Package Index (PyPI): https://pypi.org/project/redis-search-django/
You can install it by running: pip install redis-search-django
Features
- Management Command to create, update and populate the RediSearch Index.
- Auto Index on Model object Create, Update and Delete.
- Auto Index on Related Model object Add, Update, Remove and Delete.
- Easy to create Document classes (Uses Django Model Form Class like structure).
- Index nested models (e.g:
OneToOneField
,ForeignKey
andManyToManyField
). - Search documents using
redis-om
. - Search Result Pagination.
- Search Result Sorting.
- RediSearch Result to Django QuerySet.
- Faceted Search.
Submission Category:
Wacky Wildcards
(Because a Django Package does not fit into other Categories)
Language Used
- Python
Link to Code
Django Package Repository:
saadmk11 / redis-search-django
Django package that provides auto indexing and searching capabilities for Django model instances using RediSearch.
redis-search-django
About
A Django package that provides auto indexing and searching capabilities for Django model instances using RediSearch.
Features
- Management Command to create, update and populate the RediSearch Index.
- Auto Index on Model object Create, Update and Delete.
- Auto Index on Related Model object Add, Update, Remove and Delete.
- Easy to create Document classes (Uses Django Model Form Class like structure).
- Index nested models (e.g:
OneToOneField
,ForeignKey
andManyToManyField
). - Search documents using
redis-om
. - Search Result Pagination.
- Search Result Sorting.
- RediSearch Result to Django QuerySet.
- Faceted Search.
Requirements
- Python: 3.7, 3.8, 3.9, 3.10
- Django: 3.2, 4.0, 4.1
- redis-om: >= 0.0.27
Redis
Downloading Redis
The latest version of Redis is available from Redis.io. You can also install Redis with your operating system's package manager.
RediSearch and RedisJSON
redis-search-django
relies on the RediSearch and RedisJSON Redis modules to support rich queries and embedded modelsYou need these Redis
Demo App Repository:
(README file contains the details as per Hackathon Requirements)
Auto Index and Search Django Model Instances with RediSearch (using redis-search-django
)
Description
I built an Installable Django Package called redis-search-django
as a part of Redis Hackathon on DEVredis-search-django
is a package that provides auto indexing and searching capabilities for Django model instances using RediSearch.
This is a Demo App that uses redis-search-django
package to Showcase a Product Search Engine with auto indexing and searching.
redis-search-django Documentation: https://github.com/saadmk11/redis-search-django
Features
- Management Command to create, update and populate the RediSearch Index.
- Auto Index on Model object Create, Update and Delete.
- Auto Index on Related Model object Add, Update, Remove and Delete.
- Easy to create Document classes (Uses Django Model Form Class like structure).
- Index nested models (e.g:
OneToOneField
,ForeignKey
andManyToManyField
). - Search documents using
redis-om
. - Search Result Pagination.
- Search Result Sorting.
- RediSearch Result to Django QuerySet.
- Faceted Search.
App Screenshot
How it works
Create Search
Additional Resources / Info
How to use it
Create Search Document from Django Model. (Using redis-search-django
)
1. For Django Model:
# models.pyfrom django.db import modelsclass Category(models.Model): name = models.CharField(max_length=32) slug = models.SlugField(max_length=64) def __str__(self) -> str: return self.name
2. You can create a document class like this:
# documents.pyfrom redis_search_django.documents import JsonDocumentfrom .models import Categoryclass CategoryDocument(JsonDocument): class Django: model = Category fields = ["name", "slug"]
3. Run Django Management Command Index
to create the index on Redis (Only need to run once to generate Index Schema on Redis):
python manage.py index
Note: This will also populate the index with existing data from the database
Now category objects will be indexed automatically using Redis on create/update/delete events.
More Complex Examples Can be found here: https://github.com/saadmk11/redis-search-django
Screenshot of the Demo App:
- Check out Redis OM, client libraries for working with Redis as a multi-model database.
- Use RedisInsight to visualize your data in Redis.
- Sign up for a free Redis database.
Original Link: https://dev.to/saadmk11/auto-index-and-search-django-model-instances-with-redisearch-using-redis-search-django-4add
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To