About Full-text Search with Postgres

You can do a full-text search with PostgreSQL using a QuerySet like this:

1
2
3
4
5
6
7
8
9
from django.contrib.postgres.search import SearchVector
from django.contrib.postgres.search import SearchQuery
keywords = "Django Tricks"

queryset = Post.objects.annotate(
    search=SearchVector("title", "description", "author_bio")
).filter(
    search=SearchQuery(keywords)
)

Tips and Tricks Programming Databases Django 4.2 Django 3.2 Django 2.2 PostgreSQL