Cleaner implementation of the fuzzy matching fix I did; this also handels "true" multiple matches (such that there really are

>1 thing named "box" in the room); the previous implementation just picked the first occurence instead of giving a
multiple match error.
/Griatch
This commit is contained in:
Griatch 2009-09-02 17:57:54 +00:00
parent 68217072a6
commit 2aae4a0105
2 changed files with 32 additions and 32 deletions

View file

@ -11,7 +11,6 @@ from django.contrib.auth.models import User, Group
from django.conf import settings
from src.objects.util import object as util_object
from src.objects.managers.object import ObjectManager
from src.objects.managers.object import UniqueMatch
from src.objects.managers.attribute import AttributeManager
from src.config.models import ConfigValue
from src.ansi import ANSITable, parse_ansi
@ -961,22 +960,17 @@ class Object(models.Model):
if util_object.is_dbref(oname):
# First character is a pound sign, looks to be a dbref.
return self.dbref_match(oname)
else:
# Check if this is an exact match
oname = oname.lower()
oname = oname.lower()
if match_type == "exact":
#exact matching
name_chunks = self.name.lower().split(';')
# True=1, False=0, so if any hit, sum(result)>0.
exact_match = sum(map(lambda o: oname == o, name_chunks)) > 0
if match_type == "exact":
#return result outright
return exact_match
if match_type == "fuzzy":
if exact_match:
#even if a fuzzy match, an exact match is worth more
raise UniqueMatch(self)
else:
#not an exact match; use fuzzy matching
return oname in self.name.lower()
#False=0 and True=1 in python, so if sum>0, we
#have at least one exact match.
return sum(map(lambda o: oname == o, name_chunks)) > 0
else:
#fuzzy matching
return oname in self.name.lower()
def filter_contents_from_str(self, oname):
"""