Better handle partial search matches. Resolve #2579
This commit is contained in:
parent
6028844901
commit
d69589ec99
3 changed files with 12 additions and 6 deletions
|
|
@ -1035,7 +1035,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, BaseEvenniaTest):
|
||||||
pcmdset = AccountCmdSet()
|
pcmdset = AccountCmdSet()
|
||||||
pcmdset.at_cmdset_creation()
|
pcmdset.at_cmdset_creation()
|
||||||
pcmds = [cmd.key for cmd in pcmdset.commands] + ["a", "b", "c", "d"]
|
pcmds = [cmd.key for cmd in pcmdset.commands] + ["a", "b", "c", "d"]
|
||||||
self.assertTrue(all(cmd.key in pcmds for cmd in cmdset.commands))
|
self.assertEqual(set(cmd.key for cmd in cmdset.commands), set(pcmds))
|
||||||
|
|
||||||
# _callback = lambda cmdset: self.assertEqual(sum(1 for cmd in cmdset.commands if cmd.key in ("a", "b", "c", "d")), 4)
|
# _callback = lambda cmdset: self.assertEqual(sum(1 for cmd in cmdset.commands if cmd.key in ("a", "b", "c", "d")), 4)
|
||||||
deferred.addCallback(_callback)
|
deferred.addCallback(_callback)
|
||||||
|
|
|
||||||
|
|
@ -383,7 +383,7 @@ class TestPuzzles(BaseEvenniaCommandTest):
|
||||||
self._use(
|
self._use(
|
||||||
"steel-1, flint", "You try to utilize these but nothing happens ... something amiss?"
|
"steel-1, flint", "You try to utilize these but nothing happens ... something amiss?"
|
||||||
)
|
)
|
||||||
self._use("steel-1, flint, red steel, steel-3", "You are a Genius")
|
self._use("steel-1, flint, red steel, steel-2", "You are a Genius")
|
||||||
self._check_room_contents({"smoke": 1, "fire": 1})
|
self._check_room_contents({"smoke": 1, "fire": 1})
|
||||||
_box_all()
|
_box_all()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -476,13 +476,19 @@ class ObjectDBManager(TypedObjectManager):
|
||||||
# query - if so, strip it.
|
# query - if so, strip it.
|
||||||
match = _MULTIMATCH_REGEX.match(str(searchdata))
|
match = _MULTIMATCH_REGEX.match(str(searchdata))
|
||||||
match_number = None
|
match_number = None
|
||||||
|
stripped_searchdata = searchdata
|
||||||
if match:
|
if match:
|
||||||
# strips the number
|
# strips the number
|
||||||
match_number, searchdata = match.group("number"), match.group("name")
|
match_number, stripped_searchdata = match.group("number"), match.group("name")
|
||||||
match_number = int(match_number) - 1
|
match_number = int(match_number) - 1
|
||||||
if match_number is not None or not exact:
|
if match_number is not None:
|
||||||
# run search again, with the exactness set by call
|
# run search against the stripped data
|
||||||
matches = _searcher(searchdata, candidates, typeclass, exact=exact)
|
matches = _searcher(stripped_searchdata, candidates, typeclass, exact=True)
|
||||||
|
if not matches:
|
||||||
|
# final chance to get a looser match against the number-strippped query
|
||||||
|
matches = _searcher(stripped_searchdata, candidates, typeclass, exact=False)
|
||||||
|
elif not exact:
|
||||||
|
matches = _searcher(searchdata, candidates, typeclass, exact=False)
|
||||||
|
|
||||||
# deal with result
|
# deal with result
|
||||||
if len(matches) == 1 and match_number is not None and match_number != 0:
|
if len(matches) == 1 and match_number is not None and match_number != 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue