Getting started¶
Install the package, point it at Redis, declare a Document, and run your first
search.
Install¶
Add the app:
In development you can also add the debug overlay. Do not add it in production.
Redis¶
You need Redis 8+ with Query Engine (RediSearch) and RedisJSON. The redis-stack image is the easiest local setup. This repository includes a Compose file:
That publishes Redis on 6379 and Redis Insight on 8001.
Existing Redis
Point the package at it with REDIS_SEARCH["URL"]. Full settings:
Settings.
Declare a document¶
Document classes must live in a documents.py module so
AppConfig.ready() can autodiscover them.
from redis_search_django.documents import Document
from .models import Category
class CategoryDocument(Document):
class Django:
model = Category
fields = ["name", "slug"]
Create the index and load existing rows:
After that, Category rows are written to Redis on save() and removed on
delete().
Search¶
from redis_search_django import Q
from shop.documents import CategoryDocument
list(CategoryDocument.objects.filter(name__search="shoes")[:20])
Use redis_search_django.Q only. Passing django.db.models.Q is a
TypeError.