[Django]-Using django-haystack, how do I perform a search with only partial terms?

6👍

I use to have a similar problem, as workaround or maybe a Fix you can change the query lookup

results = SearchQuerySet().filter(content__startswith='Sri Ragh')

The issue is that django-haystack doesn’t implement all lingos from search engines. Of course you can do this.

results = SearchQuerySet().raw_search('READ THE SEARCH ENGINE QUERY SYNTAX FOR GET WILDCARD LOOKUPS')

As Django-haystack says, this is not portable.

-1👍

You can use icontains or startswith.

Be careful with this one, if a query is for example ‘r’, this will bring you all ‘Model’ entities that have a ‘r’ in its content.

Model.objects.filter(content__icontains=query)

Model.objects.filter(content__startswith=query)

Look at the documentation

Leave a comment