Commit 6bf28ccf authored by jnga's avatar jnga

Default to case-insensitive filtering and searching (MongoEngine).

The ability to do a case-insensitive search was added with
pull request #177. Preceding the search term with an
asterisk made the search case insensitive.

This commit makes case insensitive the default. In order to
do this while keeping case-sensitive capability, the
asterisk now means the opposite: case sensitive.

Making filtering and searching case insensitive by default
is meant to match the usual behavior of search boxes on
web sites and operating systems.
parent 000eb4e0
def parse_like_term(term):
"""
Parse search term into (operation, term) tuple. Recognizes operators
in the beginning of the search term.
in the beginning of the search term. Case insensitive is the default.
* = case insensitive (can precede other operators)
* = case sensitive (can precede other operators)
^ = starts with
= = exact
:param term:
Search term
"""
case_insensitive = term.startswith('*')
if case_insensitive:
case_sensitive = term.startswith('*')
if case_sensitive:
term = term[1:]
# apply operators
if term.startswith('^'):
......@@ -23,6 +23,6 @@ def parse_like_term(term):
else:
oper = 'contains'
# add case insensitive flag
if case_insensitive:
if not case_sensitive:
oper = 'i'+oper
return oper, term
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment