Removed SEARCH_AT_MULTIMATCH_INPUT and SEARCH_AT_MULTIMATCH_CMD settings and connected functions - these are no longer individually overloadable. SEARCH_AT_RESULT function now handles all error reporting. Also added SEARCH_MULTIMATCH_SEPARATOR to make it easy to replace the character used to separate multi-matches (1-box, 2-box is using '-' by default), in response to #795. Also moved the default SEARCH_AT_RESULT function from the cmdparser to evennia.utils.utils.
This commit is contained in:
parent
5429ede5f7
commit
2743f98fb0
10 changed files with 116 additions and 199 deletions
|
|
@ -1,13 +1,13 @@
|
|||
"""
|
||||
Custom manager for Objects.
|
||||
"""
|
||||
import re
|
||||
from itertools import chain
|
||||
from django.db.models import Q
|
||||
from django.conf import settings
|
||||
from django.db.models.fields import exceptions
|
||||
from evennia.typeclasses.managers import TypedObjectManager, TypeclassManager
|
||||
from evennia.typeclasses.managers import returns_typeclass, returns_typeclass_list
|
||||
from evennia.utils import utils
|
||||
from evennia.utils.utils import to_unicode, is_iter, make_iter, string_partial_matching
|
||||
|
||||
__all__ = ("ObjectManager",)
|
||||
|
|
@ -16,12 +16,11 @@ _GA = object.__getattribute__
|
|||
# delayed import
|
||||
_ATTR = None
|
||||
|
||||
_MULTIMATCH_REGEX = re.compile(r"([0-9]+)%s(.*)" %
|
||||
settings.SEARCH_MULTIMATCH_SEPARATOR, re.I + re.U)
|
||||
|
||||
# Try to use a custom way to parse id-tagged multimatches.
|
||||
|
||||
_AT_MULTIMATCH_INPUT = utils.variable_from_module(*settings.SEARCH_AT_MULTIMATCH_INPUT.rsplit('.', 1))
|
||||
|
||||
|
||||
class ObjectDBManager(TypedObjectManager):
|
||||
"""
|
||||
This ObjectManager implements methods for searching
|
||||
|
|
@ -379,9 +378,15 @@ class ObjectDBManager(TypedObjectManager):
|
|||
if not matches:
|
||||
# no matches found - check if we are dealing with N-keyword
|
||||
# query - if so, strip it.
|
||||
match_number, searchdata = _AT_MULTIMATCH_INPUT(searchdata)
|
||||
# run search again, with the exactness set by call
|
||||
match = _MULTIMATCH_REGEX.match(searchdata)
|
||||
match_number = None
|
||||
if match:
|
||||
# strips the number
|
||||
match_number, searchdata = match.groups()
|
||||
match_number = int(match_number) - 1
|
||||
match_number = match_number if match_number >= 0 else None
|
||||
if match_number is not None or not exact:
|
||||
# run search again, with the exactness set by call
|
||||
matches = _searcher(searchdata, candidates, typeclass, exact=exact)
|
||||
|
||||
# deal with result
|
||||
|
|
|
|||
|
|
@ -334,7 +334,8 @@ class DefaultObject(ObjectDB):
|
|||
exact=exact)
|
||||
if quiet:
|
||||
return results
|
||||
return _AT_SEARCH_RESULT(self, searchdata, results, global_search, nofound_string, multimatch_string)
|
||||
return _AT_SEARCH_RESULT(results, self, query=searchdata,
|
||||
nofound_string=nofound_string, multimatch_string=multimatch_string)
|
||||
|
||||
def search_player(self, searchdata, quiet=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue