Django text search with partial sentence match

Viewed 8210

I am building a site in which I want to implement text search for the title and description of some objects. Since I will have little amount of objects (~500 documents) I am not considering Haystack and the such.

I only need 2 features:

  • Be able to prioritize matches on the title over the description (with some kind of weight).
  • Allow partial match of the sentence. For example, if I search for 'ice cream', get also the results for 'ice' and 'cream'.

I have looked into django-watson and django-full-text-search but I am not sure if they allow partial matching. Any ideas?

6 Answers

Full text search it is now supported by Django: Django Full Text Search.

IMPORTANT: It seems this is only enabled for postgres db backend.

# Example based on Django Docs.
Entry.objects.annotate(
   search=SearchVector('title', 'description'),
).filter(search='some_text')

You could also use the search lookup

Entry.objects.filter(title__search='Cheese')
Related