Added candidates as a keyword to DefaultObject.search(). Resolves #644.
This commit is contained in:
parent
f25ea99b83
commit
6816e200b6
1 changed files with 24 additions and 15 deletions
|
|
@ -316,7 +316,8 @@ class DefaultObject(ObjectDB):
|
||||||
location=None,
|
location=None,
|
||||||
attribute_name=None,
|
attribute_name=None,
|
||||||
quiet=False,
|
quiet=False,
|
||||||
exact=False):
|
exact=False,
|
||||||
|
candidates=None):
|
||||||
"""
|
"""
|
||||||
Returns the typeclass of an Object matching a search string/condition
|
Returns the typeclass of an Object matching a search string/condition
|
||||||
|
|
||||||
|
|
@ -361,6 +362,11 @@ class DefaultObject(ObjectDB):
|
||||||
exact (bool) - if unset (default) - prefers to match to beginning of
|
exact (bool) - if unset (default) - prefers to match to beginning of
|
||||||
string rather than not matching at all. If set, requires
|
string rather than not matching at all. If set, requires
|
||||||
exact mathing of entire string.
|
exact mathing of entire string.
|
||||||
|
candidates (list of objects) - this is an optional custom list of objects
|
||||||
|
to search (filter) between. It is ignored if global_search
|
||||||
|
is given. If not set, this list will automatically be defined
|
||||||
|
to include the location, the contents of location and the
|
||||||
|
caller's contents (inventory).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
quiet=False (default):
|
quiet=False (default):
|
||||||
|
|
@ -387,27 +393,30 @@ class DefaultObject(ObjectDB):
|
||||||
# do nick-replacement on search
|
# do nick-replacement on search
|
||||||
searchdata = self.nicks.nickreplace(searchdata, categories=("object", "player"), include_player=True)
|
searchdata = self.nicks.nickreplace(searchdata, categories=("object", "player"), include_player=True)
|
||||||
|
|
||||||
candidates=None
|
|
||||||
if(global_search or (is_string and searchdata.startswith("#") and
|
if(global_search or (is_string and searchdata.startswith("#") and
|
||||||
len(searchdata) > 1 and searchdata[1:].isdigit())):
|
len(searchdata) > 1 and searchdata[1:].isdigit())):
|
||||||
# only allow exact matching if searching the entire database
|
# only allow exact matching if searching the entire database
|
||||||
# or unique #dbrefs
|
# or unique #dbrefs
|
||||||
exact = True
|
exact = True
|
||||||
elif location:
|
elif not candidates:
|
||||||
# location(s) were given
|
# no custom candidates given - get them automatically
|
||||||
candidates = []
|
|
||||||
for obj in make_iter(location):
|
|
||||||
candidates.extend(obj.contents)
|
|
||||||
else:
|
|
||||||
# local search. Candidates are self.contents, self.location
|
|
||||||
# and self.location.contents
|
|
||||||
location = self.location
|
|
||||||
candidates = self.contents
|
|
||||||
if location:
|
if location:
|
||||||
candidates = candidates + [location] + location.contents
|
# location(s) were given
|
||||||
|
candidates = []
|
||||||
|
for obj in make_iter(location):
|
||||||
|
candidates.extend(obj.contents)
|
||||||
else:
|
else:
|
||||||
# normally we are included in location.contents
|
# local search. Candidates are taken from
|
||||||
candidates.append(self)
|
# self.contents, self.location and
|
||||||
|
# self.location.contents
|
||||||
|
location = self.location
|
||||||
|
candidates = self.contents
|
||||||
|
if location:
|
||||||
|
candidates = candidates + [location] + location.contents
|
||||||
|
else:
|
||||||
|
# normally we don't need this since we are
|
||||||
|
# included in location.contents
|
||||||
|
candidates.append(self)
|
||||||
|
|
||||||
results = ObjectDB.objects.object_search(searchdata,
|
results = ObjectDB.objects.object_search(searchdata,
|
||||||
attribute_name=attribute_name,
|
attribute_name=attribute_name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue