I have a project with Django, DRF and PostgreSQL. And I need to make a search for some data in this project. In this search I need logical operators (AND, OR, NOT), searching by prefix (like manch*) and case insensitivity. So I decided to use PostgreSQL full text search like this
class VariableSearch(generics.ListAPIView):
serializer_class = VariableSerializer
def get_queryset(self):
q = self.request.query_params.get('query')
if q:
vector = SearchVector('name', 'label')
query = SearchQuery(q, search_type='raw')
queryset = Variable.objects.annotate(search=vector).filter(search=query)
else:
queryset = Variable.objects.none()
return queryset
So with this type of search I can do queries like this
http://127.0.0.1:8000/search_var/?query=полит:* | инфо:*
And operator OR and searching by prefix working good.
But when I'm trying to use AND (&) on NOT (!) it's giving me results without this logical AND or just syntax error in tsquery: "word !not"
for queries like this
http://127.0.0.1:8000/search_var/?query=word !not
So how to make AND and NOT work properly?