Better handle partial search matches. Resolve #2579

This commit is contained in:
Griatch 2022-03-01 18:28:53 +01:00
parent 82fdcf06f9
commit b407a8542c
3 changed files with 12 additions and 6 deletions

View file

@ -1035,7 +1035,7 @@ class TestGetAndMergeCmdSets(TwistedTestCase, BaseEvenniaTest):
pcmdset = AccountCmdSet()
pcmdset.at_cmdset_creation()
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)
deferred.addCallback(_callback)

View file

@ -383,7 +383,7 @@ class TestPuzzles(BaseEvenniaCommandTest):
self._use(
"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})
_box_all()

View file

@ -476,13 +476,19 @@ class ObjectDBManager(TypedObjectManager):
# query - if so, strip it.
match = _MULTIMATCH_REGEX.match(str(searchdata))
match_number = None
stripped_searchdata = searchdata
if match:
# 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
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)
if match_number is not None:
# run search against the stripped data
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
if len(matches) == 1 and match_number is not None and match_number != 0: