django-watson

raw JSON →
1.6.3 verified Fri May 01 auth: no python

Full-text multi-table search application for Django. Easy to install and use, with good performance. Current version 1.6.3. Released irregularly, last release Dec 2023.

pip install django-watson
error django.core.exceptions.ImproperlyConfigured: watson is not a registered search engine.
cause Missing 'watson' in INSTALLED_APPS or misconfigured search engine in settings.
fix
Add 'watson' to INSTALLED_APPS and ensure WATSON_BACKEND is set (default works).
error watson.search() returns empty QuerySet despite having data.
cause The model's search index has not been built or the search fields are empty.
fix
Run python manage.py buildwatson to build the search index, then verify fields contain data.
error AttributeError: module 'watson' has no attribute 'register'
cause Importing watson incorrectly or name collision.
fix
Use import watson (not from watson import ...), then call watson.register(Model).
breaking django-watson 1.6.x dropped support for Django < 3.2 and Python < 3.7. Ensure your environment meets these requirements before upgrading.
fix Upgrade Django to 3.2+ and Python to 3.7+
deprecated The `SearchContextManager` class is deprecated in favor of direct `SearchContext` usage.
fix Replace `SearchContextManager` with `SearchContext` in your code.
gotcha watson.register() must be called after all model definitions (usually at the bottom of models.py or in AppConfig.ready()). Calling it too early may cause missing models.
fix Place registration calls in the AppConfig.ready() method of your app.

Register model with watson and run a search.

import watson
from myapp.models import Article

# Register models for search
watson.register(Article)

# Perform a search
results = watson.search("query")