1

I've implemented Trigram Similarity search with annotate which gives me exactly what I want in terms of results; but I have 220,000 records in my database and the search takes 5+ seconds per query which is too long.

The search is with 3 columns and one of those invokes a join. How do I add an index or the equivalent SearchVectorField but for Trigram to speed up my query?

See current code below:

trig_vector = (
    TrigramSimilarity("make__name", text)
    + TrigramSimilarity("model", text)
    + TrigramSimilarity("specification", text)
)

query_set = (
    cls.objects.annotate(similarity=trig_vector)
    .filter(similarity__gt=0.5)
    .order_by("-similarity")
)

I have tried making my own index from various posts but I'm not too familiar with index's and each one I've implemented hasn't has an effect on the query time.

Paolo Melchiorre
  • 5,716
  • 1
  • 33
  • 52
SEMICS
  • 181
  • 3
  • 5
  • Is [this answer](https://stackoverflow.com/questions/56538419/poor-performance-when-trigram-similarity-and-full-text-search-were-combined-with/56547280#56547280) helping? – raratiru Dec 27 '20 at 20:09

0 Answers0