diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/postgres/search.txt | 21 | ||||
| -rw-r--r-- | docs/releases/2.2.txt | 4 |
2 files changed, 24 insertions, 1 deletions
diff --git a/docs/ref/contrib/postgres/search.txt b/docs/ref/contrib/postgres/search.txt index 815b423c35..1ae6233abe 100644 --- a/docs/ref/contrib/postgres/search.txt +++ b/docs/ref/contrib/postgres/search.txt @@ -70,13 +70,28 @@ and ``weight`` parameters. ``SearchQuery`` =============== -.. class:: SearchQuery(value, config=None) +.. class:: SearchQuery(value, config=None, search_type='plain') ``SearchQuery`` translates the terms the user provides into a search query object that the database compares to a search vector. By default, all the words the user provides are passed through the stemming algorithms, and then it looks for matches for all of the resulting terms. +If ``search_type`` is ``'plain'``, which is the default, the terms are treated +as separate keywords. If ``search_type`` is ``'phrase'``, the terms are treated +as a single phrase. If ``search_type`` is ``'raw'``, then you can provide a +formatted search query with terms and operators. Read PostgreSQL's `Full Text +Search docs`_ to learn about differences and syntax. Examples: + +.. _Full Text Search docs: https://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES + + >>> from django.contrib.postgres.search import SearchQuery + >>> SearchQuery('red tomato') # two keywords + >>> SearchQuery('tomato red') # same results as above + >>> SearchQuery('red tomato', search_type='phrase') # a phrase + >>> SearchQuery('tomato red', search_type='phrase') # a different phrase + >>> SearchQuery("'tomato' & ('red' | 'green')", search_type='raw') # boolean operators + ``SearchQuery`` terms can be combined logically to provide more flexibility:: >>> from django.contrib.postgres.search import SearchQuery @@ -87,6 +102,10 @@ looks for matches for all of the resulting terms. See :ref:`postgresql-fts-search-configuration` for an explanation of the ``config`` parameter. +.. versionadded:: 2.2 + + The `search_type` parameter was added. + ``SearchRank`` ============== diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index bf5bc30cde..8a94ef5e98 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -90,6 +90,10 @@ Minor features * :class:`~django.contrib.postgres.indexes.BrinIndex` now has the ``autosummarize`` parameter. +* The new ``search_type`` parameter of + :class:`~django.contrib.postgres.search.SearchQuery` allows searching for + a phrase or raw expression. + :mod:`django.contrib.redirects` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
