mirror of
https://github.com/django/django.git
synced 2025-10-12 00:09:11 +00:00
[5.2.x] Refs #25508 -- Used QuerySet.__repr__ in docs/ref/contrib/postgres/search.txt.
Backport of efb96138b4af774c22ae6e949410b45d69960357 from main.
This commit is contained in:
parent
7554c54e5f
commit
b2773a39a3
@ -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``
|
||||
@ -137,7 +137,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.
|
||||
@ -235,7 +235,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:
|
||||
|
||||
@ -245,7 +245,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:
|
||||
|
||||
@ -313,7 +313,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
|
||||
|
||||
@ -352,7 +352,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``
|
||||
-------------------------
|
||||
@ -375,7 +375,7 @@ Usage example:
|
||||
... ).filter(
|
||||
... similarity__gt=0.3
|
||||
... ).order_by("-similarity")
|
||||
[<Author: Katy Stevens>]
|
||||
<QuerySet [<Author: Katy Stevens>]>
|
||||
|
||||
``TrigramStrictWordSimilarity``
|
||||
-------------------------------
|
||||
@ -408,7 +408,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``
|
||||
-----------------------
|
||||
@ -431,7 +431,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