Skip to content
etianen edited this page Jul 19, 2012 · 34 revisions

Getting started with django-watson

To install django-watson, follow these steps:

  1. Checkout the latest django-watson release and copy or symlink the src/watson directory into your PYTHONPATH.
  2. Add 'watson' to your INSTALLED_APPS setting.
  3. Run the command manage.py syncdb.
  4. Run the command manage.py installwatson.

If you're using south in your project, then it's even easier! Just follow steps 1 and 2, then run manage.py migrate watson to comlete your installation.

Existing website data: If you're integrating django-watson with an existing site, then you'll also want to run ./manage.py buildwatson to index your existing data.

Registering models with django-watson

If you want to use django-watson to search your models, then you first need to tell it which models to include in it's indexes. To do this, simply call watson.register() for each of the models you want to index. A good place to do this is in your models.py file, since that will ensure any django management commands will recognise the registration:

import watson

watson.register(YourModel)
watson.register(YourOtherModel)

Once you've registered your models with django-watson, run the command manage.py buildwatson to register any existing models in you database. From now on, any additions, creations or deletions you make will automatically applied, so this command only needs to be run whenever you add a new model to django-watson.

For more information about registering models with django-watson, please visit the registering models wiki page.

Searching for models

You can search for any registered models using the watson.search() method:

search_results = watson.search("Your search text")

for result in search_results:
    print result.title, result.url

For more information about searching for models with django-watson, please visit the searching models wiki page.

More information

Clone this wiki locally