A don't-care value leaves a search attribute unspecified, so that attribute imposes no matching constraint. In a book catalogue, omitting an attribute from the target makes it match any corresponding value in the catalogue. section 2.3.4 section 3.8
A don't-care search works by narrowing only on supplied constraints:
- The target may provide any number of desired attribute values. section 3.8
- The catalogue checks every key–value pair present in the target. section 2.3.4
- A missing target key is not matched, allowing any catalogue value for that attribute. section 2.3.4
- Supplied string values still compare case-insensitively, while typed values retain their required datatypes. section 2.3.4
Search by kind, author, and genre
A target containing KIND: fiction, LAST: "KING", and GENRE: horror leaves title, first name, year, and other omitted attributes as don't-care values. The search returns both Carrie and It: A Novel because their supplied target values match.
Listing 2.19 (Program 2.4 Books-4): attributes.py (part 2 of 3)
...
def _is_matching_key_value(self, target_key, target_value):
if target_key not in self._dictionary.keys(): return False #1
if self._dictionary[target_key] == target_value: return True #2
if isinstance(target_value, str): #3
return Attributes._equal_ignore_case(
self._dictionary[target_key], target_value)
return False
def is_match(self, target_attrs):
for target_key, target_value \
in target_attrs._dictionary.items():
if not self._is_matching_key_value(target_key,
target_value):
return False
return True
...
Inspect the matching loop and see how iterating over target attributes makes omitted attributes don't-care values. section 2.3.4
