<commit_before>======
Search
======

A common task for web applications is to search some data in the database with
user input. In a simple case, this could be filtering a list of objects by a
category. A more complex use case might require searching with weighting,
categorization, highlighting, multiple languages, and so on. This document
explains some of the possible use cases and the tools you can use.

We'll refer to the same models used in :doc:`/topics/db/queries`.

Use Cases
=========

Standard textual queries
------------------------

Text-based fields have a selection of simple matching operations. For example,
you may wish to allow lookup up an author like so::

    >>> Author.objects.filter(name__contains='Terry')
    [<Author: <NAME>>, <Author: <NAME>>]

This is a very fragile solution as it requires the user to know an exact
substring of the author's name. A better approach could be a case-insensitive
match (:lookup:`icontains`), but this is only marginally better.

A database's more advanced comparison functions
-----------------------------------------------

If you're using PostgreSQL, Django provides :doc:`a selection of database<commit_msg>Corrected typo in search docs. (#11673)<commit_after>======
Search
======

A common task for web applications is to search some data in the database with
user input. In a simple case, this could be filtering a list of objects by a
category. A more complex use case might require searching with weighting,
categorization, highlighting, multiple languages, and so on. This document
explains some of the possible use cases and the tools you can use.

We'll refer to the same models used in :doc:`/topics/db/queries`.

Use Cases
=========

Standard textual queries
------------------------

Text-based fields have a selection of simple matching operations. For example,
you may wish to allow lookup of an author like so::

    >>> Author.objects.filter(name__contains='Terry')
    [<Author: <NAME>>, <Author: <NAME>>]

This is a very fragile solution as it requires the user to know an exact
substring of the author's name. A better approach could be a case-insensitive
match (:lookup:`icontains`), but this is only marginally better.

A database's more advanced comparison functions
-----------------------------------------------

If you're using PostgreSQL, Django provides :doc:`a selection of database
{'fraction_non_alphanumeric': 0.1345668629100084, 'fraction_numerical': 0.0021026072329688814, 'mean_word_length': 3.430167597765363, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1519730', 'n_tokens_mistral': 604, 'n_tokens_neox': 564, 'n_words': 320}