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

@ -15,15 +15,9 @@ from src.objects.exceptions import ObjectNotExist
from src.objects.util import object as util_object
from src import defines_global
from src import logger
class UniqueMatch(Exception):
"""
This allows a fuzzy match to give precedence to a perfect match.
"""
def __init__(self,matchobj):
self.matchobj = matchobj
class ObjectManager(models.Manager):
def num_total_players(self):
"""
Returns the total number of registered players.
@ -112,18 +106,30 @@ class ObjectManager(models.Manager):
"""
if dbref_only:
if limit_types:
return [prospect for prospect in searchlist if prospect.dbref_match(ostring) and prospect.type in limit_types]
return [prospect for prospect in searchlist if prospect.dbref_match(ostring)
and prospect.type in limit_types]
else:
return [prospect for prospect in searchlist if prospect.dbref_match(ostring)]
else:
try:
if limit_types:
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type) and prospect.type in limit_types]
else:
if limit_types:
results = [prospect for prospect in searchlist
if prospect.name_match(ostring, match_type=match_type)
and prospect.type in limit_types]
else:
results = [prospect for prospect in searchlist
if prospect.name_match(ostring, match_type=match_type)]
if match_type == "exact":
return results
else:
#fuzzy matching; run second sweep to catch exact matches
exact_results = [prospect for prospect in results
if prospect.name_match(ostring, match_type="exact")]
if exact_results:
return exact_results
else:
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
except UniqueMatch, e:
return [e.matchobj]
return results
def object_totals(self):
"""