From f5e347a6402c1996a8f7063de4b314bae4a55683 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 17 Sep 2018 18:03:52 +0200 Subject: Fixed #27899 -- Added support for phrase/raw searching in SearchQuery. Thanks Tim Graham, Nick Pope, and Claude Paroz for contribution and review. --- docs/ref/contrib/postgres/search.txt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'docs/ref') 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`` ============== -- cgit v1.3