mirror of
https://github.com/django/django.git
synced 2025-09-24 23:49:12 +00:00
[6.0.x] Refs #25508 -- Used QuerySet.__repr__ in docs/ref/contrib/postgres/search.txt.
Backport of efb96138b4af774c22ae6e949410b45d69960357 from main.
This commit is contained in:
parent
5d00bbd41d
commit
fd94c90526
@ -27,7 +27,7 @@ single column in the database. For example:
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> 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
|
||||
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(
|
||||
... search=SearchVector("body_text", "blog__tagline"),
|
||||
... ).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
|
||||
:class:`~django.db.models.Expression` or the name of a field. Multiple
|
||||
@ -67,7 +67,7 @@ For example:
|
||||
>>> Entry.objects.annotate(
|
||||
... search=SearchVector("body_text") + SearchVector("blog__tagline"),
|
||||
... ).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
|
||||
:ref:`postgresql-fts-weighting-queries` for an explanation of the ``config``
|
||||
@ -142,7 +142,7 @@ order by relevancy:
|
||||
>>> vector = SearchVector("body_text")
|
||||
>>> query = SearchQuery("cheese")
|
||||
>>> 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
|
||||
``weights`` parameter.
|
||||
@ -240,7 +240,7 @@ different language parsers and dictionaries as defined by the database:
|
||||
>>> Entry.objects.annotate(
|
||||
... search=SearchVector("body_text", 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:
|
||||
|
||||
@ -250,7 +250,7 @@ The value of ``config`` could also be stored in another column:
|
||||
>>> Entry.objects.annotate(
|
||||
... search=SearchVector("body_text", config=F("blog__language")),
|
||||
... ).filter(search=SearchQuery("œuf", config=F("blog__language")))
|
||||
[<Entry: Pain perdu>]
|
||||
<QuerySet [<Entry: Pain perdu>]>
|
||||
|
||||
.. _postgresql-fts-weighting-queries:
|
||||
|
||||
@ -364,7 +364,7 @@ if it were an annotated ``SearchVector``:
|
||||
|
||||
>>> Entry.objects.update(search_vector=SearchVector("body_text"))
|
||||
>>> 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
|
||||
|
||||
@ -403,7 +403,7 @@ Usage example:
|
||||
... ).filter(
|
||||
... similarity__gt=0.3
|
||||
... ).order_by("-similarity")
|
||||
[<Author: Katy Stevens>, <Author: Stephen Keats>]
|
||||
<QuerySet [<Author: Katy Stevens>, <Author: Stephen Keats>]>
|
||||
|
||||
``TrigramWordSimilarity``
|
||||
-------------------------
|
||||
@ -426,7 +426,7 @@ Usage example:
|
||||
... ).filter(
|
||||
... similarity__gt=0.3
|
||||
... ).order_by("-similarity")
|
||||
[<Author: Katy Stevens>]
|
||||
<QuerySet [<Author: Katy Stevens>]>
|
||||
|
||||
``TrigramStrictWordSimilarity``
|
||||
-------------------------------
|
||||
@ -459,7 +459,7 @@ Usage example:
|
||||
... ).filter(
|
||||
... distance__lte=0.7
|
||||
... ).order_by("distance")
|
||||
[<Author: Katy Stevens>, <Author: Stephen Keats>]
|
||||
<QuerySet [<Author: Katy Stevens>, <Author: Stephen Keats>]>
|
||||
|
||||
``TrigramWordDistance``
|
||||
-----------------------
|
||||
@ -482,7 +482,7 @@ Usage example:
|
||||
... ).filter(
|
||||
... distance__lte=0.7
|
||||
... ).order_by("distance")
|
||||
[<Author: Katy Stevens>]
|
||||
<QuerySet [<Author: Katy Stevens>]>
|
||||
|
||||
``TrigramStrictWordDistance``
|
||||
-----------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user