Question

I've got a Haystack/xapian search index for django.contrib.auth.models.User. The template is simply

{{object.get_full_name}}

as I intend for a user to type in a name and be able to search for it.

My issue is this: if I search, say, Sri (my full first name) I come up with a result for the user object pertaining to my name. However, if I search Sri Ragh - that is, my full name, and part of my last name, I get no results.

How can I set Haystack up so that I can get the appropriate results for partial queries? (I essentially want it to search *Sri Ragh*, but I don't know if wildcards would actually do the trick, or how to implement them).

This is my search query:

results = SearchQuerySet().filter(content='Sri Ragh')
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top