1
0
mirror of https://github.com/django/django.git synced 2025-09-25 07:59:11 +00:00

Refs #25508 -- Used QuerySet.__repr__ in docs/ref/contrib/postgres/search.txt.

This commit is contained in:
Jacob Walls 2025-09-23 07:14:31 -04:00
parent 9af8225117
commit efb96138b4

View File

@ -27,7 +27,7 @@ single column in the database. For example:
.. code-block:: pycon .. code-block:: pycon
>>> Entry.objects.filter(body_text__search="Cheese") >>> Entry.objects.filter(body_text__search="Cheese")
[<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>] <QuerySet [<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>]>
This creates a ``to_tsvector`` in the database from the ``body_text`` field This creates a ``to_tsvector`` in the database from the ``body_text`` field
and a ``plainto_tsquery`` from the search term ``'Cheese'``, both using the and a ``plainto_tsquery`` from the search term ``'Cheese'``, both using the
@ -52,7 +52,7 @@ To query against both fields, use a ``SearchVector``:
>>> Entry.objects.annotate( >>> Entry.objects.annotate(
... search=SearchVector("body_text", "blog__tagline"), ... search=SearchVector("body_text", "blog__tagline"),
... ).filter(search="Cheese") ... ).filter(search="Cheese")
[<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>] <QuerySet [<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>]>
The arguments to ``SearchVector`` can be any The arguments to ``SearchVector`` can be any
:class:`~django.db.models.Expression` or the name of a field. Multiple :class:`~django.db.models.Expression` or the name of a field. Multiple
@ -67,7 +67,7 @@ For example:
>>> Entry.objects.annotate( >>> Entry.objects.annotate(
... search=SearchVector("body_text") + SearchVector("blog__tagline"), ... search=SearchVector("body_text") + SearchVector("blog__tagline"),
... ).filter(search="Cheese") ... ).filter(search="Cheese")
[<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>] <QuerySet [<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>]>
See :ref:`postgresql-fts-search-configuration` and See :ref:`postgresql-fts-search-configuration` and
:ref:`postgresql-fts-weighting-queries` for an explanation of the ``config`` :ref:`postgresql-fts-weighting-queries` for an explanation of the ``config``
@ -142,7 +142,7 @@ order by relevancy:
>>> vector = SearchVector("body_text") >>> vector = SearchVector("body_text")
>>> query = SearchQuery("cheese") >>> query = SearchQuery("cheese")
>>> Entry.objects.annotate(rank=SearchRank(vector, query)).order_by("-rank") >>> Entry.objects.annotate(rank=SearchRank(vector, query)).order_by("-rank")
[<Entry: Cheese on Toast recipes>, <Entry: Pizza recipes>] <QuerySet [<Entry: Cheese on Toast recipes>, <Entry: Pizza recipes>]>
See :ref:`postgresql-fts-weighting-queries` for an explanation of the See :ref:`postgresql-fts-weighting-queries` for an explanation of the
``weights`` parameter. ``weights`` parameter.
@ -240,7 +240,7 @@ different language parsers and dictionaries as defined by the database:
>>> Entry.objects.annotate( >>> Entry.objects.annotate(
... search=SearchVector("body_text", config="french"), ... search=SearchVector("body_text", config="french"),
... ).filter(search=SearchQuery("œuf", config="french")) ... ).filter(search=SearchQuery("œuf", config="french"))
[<Entry: Pain perdu>] <QuerySet [<Entry: Pain perdu>]>
The value of ``config`` could also be stored in another column: The value of ``config`` could also be stored in another column:
@ -250,7 +250,7 @@ The value of ``config`` could also be stored in another column:
>>> Entry.objects.annotate( >>> Entry.objects.annotate(
... search=SearchVector("body_text", config=F("blog__language")), ... search=SearchVector("body_text", config=F("blog__language")),
... ).filter(search=SearchQuery("œuf", config=F("blog__language"))) ... ).filter(search=SearchQuery("œuf", config=F("blog__language")))
[<Entry: Pain perdu>] <QuerySet [<Entry: Pain perdu>]>
.. _postgresql-fts-weighting-queries: .. _postgresql-fts-weighting-queries:
@ -364,7 +364,7 @@ if it were an annotated ``SearchVector``:
>>> Entry.objects.update(search_vector=SearchVector("body_text")) >>> Entry.objects.update(search_vector=SearchVector("body_text"))
>>> Entry.objects.filter(search_vector="cheese") >>> Entry.objects.filter(search_vector="cheese")
[<Entry: Cheese on Toast recipes>, <Entry: Pizza recipes>] <QuerySet [<Entry: Cheese on Toast recipes>, <Entry: Pizza recipes>]>
.. _PostgreSQL documentation: https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS .. _PostgreSQL documentation: https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS
@ -403,7 +403,7 @@ Usage example:
... ).filter( ... ).filter(
... similarity__gt=0.3 ... similarity__gt=0.3
... ).order_by("-similarity") ... ).order_by("-similarity")
[<Author: Katy Stevens>, <Author: Stephen Keats>] <QuerySet [<Author: Katy Stevens>, <Author: Stephen Keats>]>
``TrigramWordSimilarity`` ``TrigramWordSimilarity``
------------------------- -------------------------
@ -426,7 +426,7 @@ Usage example:
... ).filter( ... ).filter(
... similarity__gt=0.3 ... similarity__gt=0.3
... ).order_by("-similarity") ... ).order_by("-similarity")
[<Author: Katy Stevens>] <QuerySet [<Author: Katy Stevens>]>
``TrigramStrictWordSimilarity`` ``TrigramStrictWordSimilarity``
------------------------------- -------------------------------
@ -459,7 +459,7 @@ Usage example:
... ).filter( ... ).filter(
... distance__lte=0.7 ... distance__lte=0.7
... ).order_by("distance") ... ).order_by("distance")
[<Author: Katy Stevens>, <Author: Stephen Keats>] <QuerySet [<Author: Katy Stevens>, <Author: Stephen Keats>]>
``TrigramWordDistance`` ``TrigramWordDistance``
----------------------- -----------------------
@ -482,7 +482,7 @@ Usage example:
... ).filter( ... ).filter(
... distance__lte=0.7 ... distance__lte=0.7
... ).order_by("distance") ... ).order_by("distance")
[<Author: Katy Stevens>] <QuerySet [<Author: Katy Stevens>]>
``TrigramStrictWordDistance`` ``TrigramStrictWordDistance``
----------------------------- -----------------------------