Commit 4fb819f9 authored by Christopher Bess's avatar Christopher Bess

- add support for case-insensitive search

- supports case-insensitive searches
- update comments
parent 7600278b
def parse_like_term(term):
"""
Parse search term into (operation, term) tuple
Parse search term into (operation, term) tuple. Recognizes operators
in the begining of the search term.
* = case insensitive (can preceed other operators)
^ = starts with
= = exact
:param term:
Search term
"""
case_insensitive = term.startswith('*')
if case_insensitive:
term = term[1:]
# apply operators
if term.startswith('^'):
return 'startswith', term[1:]
oper = 'startswith'
term = term[1:]
elif term.startswith('='):
return 'exact', term[1:]
return 'contains', term
oper = 'exact'
term = term[1:]
else:
oper = 'contains'
# add case insensitive flag
if case_insensitive:
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