For search I want to use the search vector from PostgreSQL;
I wrote a custom query method:
def search(self, text):
search_vectors = (
SearchVector('name', weight='A', config='english') +
SearchVector('short_description', weight='B', config='english') +
SearchVector('description', weight='C', config='english')
)
search_query = SearchQuery(text)
search_rank = SearchRank(search_vectors, search_query, weights=[0.2, 0.4, 0.6, 1])
return self.annotate(rank=search_rank).filter(rank__gte=0.2).order_by('-rank').
There are 2 'issues'. For example for the name 'Eric', if I search:
- 'eric' I get the correct results
- 'eric john' I get not result
- 'eri' I get no results
I kind of understand why it fails, but I don't how to implement the fixes.