diff --git a/evennia/objects/manager.py b/evennia/objects/manager.py index a21a23de52..82eae2a1bc 100644 --- a/evennia/objects/manager.py +++ b/evennia/objects/manager.py @@ -431,6 +431,7 @@ class ObjectDBManager(TypedObjectManager): return matches # alias for backwards compatibility object_search = search_object + search = search_object # # ObjectManager Copy method diff --git a/evennia/typeclasses/managers.py b/evennia/typeclasses/managers.py index 26466dee07..523823a98f 100644 --- a/evennia/typeclasses/managers.py +++ b/evennia/typeclasses/managers.py @@ -356,57 +356,6 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): tag.save() return make_iter(tag)[0] - # object-manager methods - def smart_search(self, query): - """ - Search by supplying a string with optional extra search criteria to aid the query. - - Args: - query (str): A search criteria that accepts extra search criteria on the - following forms: [key|alias|#dbref...] [tag==[:category]...] [attr==::category...] - " != " != " - Returns: - matches (queryset): A queryset result matching all queries exactly. If wanting to use spaces or - ==, != in tags or attributes, enclose them in quotes. - - Note: - The flexibility of this method is limited by the input line format. Tag/attribute - matching only works for matching primitives. For even more complex queries, such as - 'in' operations or object field matching, use the full django query language. - - """ - # shlex splits by spaces unless escaped by quotes - querysplit = shlex.split(to_unicode(query, force=True)) - queries, plustags, plusattrs, negtags, negattrs = [], [], [], [], [] - 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 - if key.startswith('tag=='): - plustags.append((key[5:], rest)) - continue - elif key.startswith('tag!='): - negtags.append((key[5:], rest)) - continue - # attrs are on the form attr:value or attr:value:category - elif rest: - value, category = rest, "" - if ":" in rest: - value, category = rest.split(':', 1) - if key.startswith('attr=='): - plusattrs.append((key[7:], value, category)) - continue - elif key.startswith('attr!='): - negattrs.append((key[7:], value, category)) - continue - # if we get here, we are entering a key search criterion which - # we assume is one word. - queries.append(part) - # build query from components - query = ' '.join(queries) - - def dbref(self, dbref, reqhash=True): """ Determing if input is a valid dbref. @@ -565,6 +514,58 @@ class TypeclassManager(TypedObjectManager): """ + # object-manager methods + def smart_search(self, query): + """ + Search by supplying a string with optional extra search criteria to aid the query. + + Args: + query (str): A search criteria that accepts extra search criteria on the + + following forms: [key|alias|#dbref...] [tag==[:category]...] [attr==::category...] + " != " != " + Returns: + matches (queryset): A queryset result matching all queries exactly. If wanting to use spaces or + ==, != in tags or attributes, enclose them in quotes. + + Note: + The flexibility of this method is limited by the input line format. Tag/attribute + matching only works for matching primitives. For even more complex queries, such as + 'in' operations or object field matching, use the full django query language. + + """ + # shlex splits by spaces unless escaped by quotes + querysplit = shlex.split(to_unicode(query, force=True)) + queries, plustags, plusattrs, negtags, negattrs = [], [], [], [], [] + 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 + if key.startswith('tag=='): + plustags.append((key[5:], rest)) + continue + elif key.startswith('tag!='): + negtags.append((key[5:], rest)) + continue + # attrs are on the form attr:value or attr:value:category + elif rest: + value, category = rest, "" + if ":" in rest: + value, category = rest.split(':', 1) + if key.startswith('attr=='): + plusattrs.append((key[7:], value, category)) + continue + elif key.startswith('attr!='): + negattrs.append((key[7:], value, category)) + continue + # if we get here, we are entering a key search criterion which + # we assume is one word. + queries.append(part) + # build query from components + query = ' '.join(queries) + #TODO + def get(self, *args, **kwargs): """ Overload the standard get. This will limit itself to only