Add unfinished smart_search manager method for future use with the olc.

This commit is contained in:
Griatch 2017-04-19 06:40:24 +02:00
parent f718a1aadd
commit 4b38642666

View file

@ -375,36 +375,36 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
'in' operations or object field matching, use the full django query language. 'in' operations or object field matching, use the full django query language.
""" """
RE_TAG=
# shlex splits by spaces unless escaped by quotes # shlex splits by spaces unless escaped by quotes
querysplit = shlex.split(to_unicode(query, force=True)) querysplit = shlex.split(to_unicode(query, force=True))
plustags, plusattrs, negtags, negattrs = [], [], [], [] queries, plustags, plusattrs, negtags, negattrs = [], [], [], [], []
for ipart, part in enumerate(querysplit): for ipart, part in enumerate(querysplit):
key, rest = part, ""
if ":" in part:
key, rest = part.split(':', 1)
# tags are on the form tag or tag:category # tags are on the form tag or tag:category
if part.startswith('tag==') or part.startswith('tag!='): if key.startswith('tag=='):
tagstr, category = part, None plustags.append((key[5:], rest))
if ":" in part: continue
tagstr, category = part.split(':', 1) elif key.startswith('tag!='):
plustags.append((tagstr, category)) negtags.append((key[5:], rest))
elif part.startswith('tag!='): continue
tagstr, category = part, None # attrs are on the form attr:value or attr:value:category
if ":" in part: elif rest:
tagstr, category = part.split(':', 1) value, category = rest, ""
negtags.append((tagstr, category)) if ":" in rest:
elif part.startswith('attr=='): value, category = rest.split(':', 1)
# if key.startswith('attr=='):
tagstr, category = part, None plusattrs.append((key[7:], value, category))
if ":" in part: continue
tagstr, category = part.split(':', 1) elif key.startswith('attr!='):
negtags.append((tagstr, category)) negattrs.append((key[7:], value, category))
continue
# if we get here, we are entering a key search criterion which
# we assume is one word.
tags = [part.split(':', 1) if ':' in part else (part, None) queries.append(part)
for part in spacesplit if part.startswith('tag==') or part.startswith('tag!=')] # build query from components
attrs = query = ' '.join(queries)
def dbref(self, dbref, reqhash=True): def dbref(self, dbref, reqhash=True):