#33459: Explain how to optimize full text search with SearchVectorField and
GinIndex
-------------------------------------+-------------------------------------
Reporter: Thomas Aglassinger | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 4.0
Severity: Normal | Resolution: wontfix
Keywords: postgres | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):
> I found this too abstract to apply immediately and would have liked an
example similar to the one included in the proposed patch. At least
something like:
>
> {{{
> from django.contrib.postgres.indexes import GinIndex
> from django.contrib.postgres.search import SearchVectorField
>
> class Entry(models.Model):
> ... # same data fields as before
> search_vector = models.SearchVectorField(null=True)
>
> class Meta:
> indexes = [GinIndex(fields=['search_vector']]
> }}}
> Yes, everything shown here is explained one way or the other in the
paragraphs before but it took me a while to turn these general and
abstract descriptions into the code above. Unlike all the other parts in
this chapter, which have a concise and well written example for the
concepts they explain.
In the
[https://docs.djangoproject.com/en/dev/ref/contrib/postgres/search/#performance
Performance] section we're talking about ''"**a functional index** which
matches the search vector you wish to use"'' so rather
{{{
GinIndex(SearchVector('body_text'), name='body_search_vector_idx')
}}}
What do you think about adding?
{{{#!diff
diff --git a/docs/ref/contrib/postgres/search.txt
b/docs/ref/contrib/postgres/search.txt
index cfed877d9c..fa369670bb 100644
--- a/docs/ref/contrib/postgres/search.txt
+++ b/docs/ref/contrib/postgres/search.txt
@@ -255,8 +255,14 @@ run into performance problems. Full text search is a
more intensive process
than comparing the size of an integer, for example.
In the event that all the fields you're querying on are contained within
one
-particular model, you can create a functional index which matches the
search
-vector you wish to use. The PostgreSQL documentation has details on
+particular model, you can create a functional
+:class:`GIN <django.contrib.postgres.indexes.GinIndex>` or
+:class:`GiST <django.contrib.postgres.indexes.GistIndex>` index which
matches
+the search vector you wish to use. For example::
+
+ GinIndex(SearchVector('body_text'), name='body_search_vector_idx')
+
+The PostgreSQL documentation has details on
`creating indexes for full text search
<https://www.postgresql.org/docs/current/textsearch-tables.html
#TEXTSEARCH-TABLES-INDEX>`_.
}}}
Would you like to prepare a patch? (if you like it of course)
--
Ticket URL: <https://code.djangoproject.com/ticket/33459#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.3bb921c275996d48c444dd8094cf2a8d%40djangoproject.com.