Fixes multiple issues with searching.
* dbref now respect candidate lists. Previously a dbref match would ignore candidates which permitted you to drop any object from anywhere by specifying a dbref. * If candidates is [], we now return right away. Without this, a candidate list of [] would not filter out anything because short circuiting like: cand_restriction = candidates and Q(pk__in=candidates_id) or Q() will use Q() (what we really want is nothing to match). This would permit you to drop any object you can refer by nick or name if your inventory was empty. * Minor fix of 'ret_index' for typo'ed 'reg_index'.
This commit is contained in:
parent
c0a4f62e95
commit
904884d4ed
1 changed files with 13 additions and 6 deletions
|
|
@ -206,7 +206,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
# fuzzy matching - first check with keys, then with aliases
|
# fuzzy matching - first check with keys, then with aliases
|
||||||
key_candidates = self.filter(Q(db_key__istartswith=ostring) | Q(alias__db_key__istartswith=ostring)).distinct()
|
key_candidates = self.filter(Q(db_key__istartswith=ostring) | Q(alias__db_key__istartswith=ostring)).distinct()
|
||||||
key_strings = key_candidates.values_list("db_key", flat=True)
|
key_strings = key_candidates.values_list("db_key", flat=True)
|
||||||
matches = string_partial_matching(key_candidates, ostring, reg_index=False)
|
matches = string_partial_matching(key_candidates, ostring, ret_index=False)
|
||||||
if matches:
|
if matches:
|
||||||
return matches
|
return matches
|
||||||
alias_candidates = self.model.alias_set.related.model.objects.filter(db_obj__pk__in=candidates_id).values_list("db_key", flat=True)
|
alias_candidates = self.model.alias_set.related.model.objects.filter(db_obj__pk__in=candidates_id).values_list("db_key", flat=True)
|
||||||
|
|
@ -267,16 +267,23 @@ class ObjectManager(TypedObjectManager):
|
||||||
if not ostring and ostring != 0:
|
if not ostring and ostring != 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# Convenience check to make sure candidates are really dbobjs
|
||||||
|
if candidates:
|
||||||
|
candidates = [cand.dbobj for cand in make_iter(candidates) if hasattr(cand, "dbobj")]
|
||||||
|
|
||||||
|
# If there are no candidates, don't go any further.
|
||||||
|
if candidates == []:
|
||||||
|
return []
|
||||||
|
|
||||||
dbref = not attribute_name and self.dbref(ostring)
|
dbref = not attribute_name and self.dbref(ostring)
|
||||||
if dbref or dbref == 0:
|
if dbref or dbref == 0:
|
||||||
# Easiest case - dbref matching (always exact)
|
# Easiest case - dbref matching (always exact)
|
||||||
dbref_match = self.dbref_search(dbref)
|
dbref_match = self.dbref_search(dbref)
|
||||||
if dbref_match:
|
if dbref_match:
|
||||||
|
if candidates == None or dbref_match.dbobj in candidates:
|
||||||
return [dbref_match]
|
return [dbref_match]
|
||||||
|
else:
|
||||||
# Convenience check to make sure candidates are really dbobjs
|
return []
|
||||||
if candidates:
|
|
||||||
candidates = [cand.dbobj for cand in make_iter(candidates) if hasattr(cand, "dbobj")]
|
|
||||||
|
|
||||||
# Search through all possibilities.
|
# Search through all possibilities.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue