etianen/django-watson — pull request #22 by neverho0d (2013-07-05 06:54:16+00:00)
Title: Row-level (or per instance) language specification for FTS

This patch allows to use some field in base model to be considered by watson for creating ts_vector. This gives ability to use different languages for different instances of base model.
For example:

class MyModel(models.Model):
search_language = models.CharField(_("Language for search index"),
max_length=24,
default="russian")
content = models.TextField()

watson.register(MyModel, search_config='search_language')

then we can use watson.search() and filter() with search_config paramer for particuar searching, e.g. in some view:

if request.LANGUAGE_CODE == 'ru':
res = watson.search(query, models=(model,), search_config='russian')
else:
res = watson.search(query, models=(model,)) # for default search config

NOTE: There isn't any tests yet, but code was checked on sample data.
Please review this code