I'm creating a search engine on my platform. I do a search for content title, description and tags inside it. Here is the code:
questions = Question.objects.filter(reduce(lambda x, y: x | y, [(Q(name__icontains=word) | Q(description__icontains=word) | Q(tags__name__icontains=word)) for word in words]))
That way, I can break the words in the text and do a pretty cool search. The problem is, I would like to sort by a priority that I create, in case I wanted to do in the following order:
In this way I will first display the result that is exactly what the user is looking for, then results that begin with what he searches for, finishes and contains.
But with my code I can not see a way to do this other than by doing the pure sql using case when .