I am implementing a search function for my API to return the object's properties when requested. So far I have tried to use Full Text Search which is usable but it has these annoying things: words have to be spelled correctly for the results to be returned and partial search, for example "appl" instead of "apple", won't work. I have also tried Trigram Similarity but it failed for long sentences. How do I implement a search function that is both accurate and fuzzy in Django?
This works
This won't work
This is my views.py
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import api_view
from .models import Object_Locations
from .serializers import Object_LocationsSerializer
from django.contrib.postgres.search import SearchVector, SearchQuery
def index(request):
return render(request, 'main/base.html', {})
@api_view(['GET',])
def LocationsList(request):
if request.method == 'GET':
vector = SearchVector('name', 'desc', 'catergory')
query = request.GET.get('search')
if query:
locations = Object_Locations.objects.annotate(search=vector,).filter(search=SearchQuery(query))
else:
locations = Object_Locations.objects.all()
serializer = Object_LocationsSerializer(locations, many=True)
return Response(serializer.data)


