Support incomplete model suffixes

This commit is contained in:
Fiden committed 2026-08-07 18:47:52 +03:00
1 parent 42f8f07207
commit 6a2d912ca5
6 files changed
+113 -5

No files matched your search

+22 -4
View File
@@ -10,6 +10,7 @@ from app.attributes import (
Compatibility,
ParsedAttributes,
compare_attributes,
model_code_matches,
parse_attributes,
)
from app.catalog import CatalogItem, build_catalog, load_raw_catalog
@@ -109,11 +110,15 @@ class CatalogMatcher:
product_types = {self.items[index].product_type for index in model_candidates}
if len(product_types) == 1:
product_type = next(iter(product_types))
exact_model = all(
code in self.model_index
for code in provisional_attributes.model_codes
)
product_match = ProductTypeMatch(
canonical=product_type,
score=1.0,
exact=True,
alias="model_code",
score=1.0 if exact_model else 0.93,
exact=exact_model,
alias="model_code" if exact_model else "model_code_prefix",
token_start=0,
)
if product_match is None and provisional_attributes.teeth is not None:
@@ -393,7 +398,20 @@ class CatalogMatcher:
def _model_candidates(self, model_codes: frozenset[str]) -> frozenset[int]:
if not model_codes:
return frozenset()
sets = [self.model_index.get(code, frozenset()) for code in model_codes]
sets: list[frozenset[int]] = []
for query_code in model_codes:
exact = self.model_index.get(query_code)
if exact:
sets.append(exact)
continue
partial_indexes: set[int] = set()
for candidate_code, indexes in self.model_index.items():
if model_code_matches(query_code, candidate_code):
partial_indexes.update(indexes)
sets.append(frozenset(partial_indexes))
if not sets or any(not indexes for indexes in sets):
return frozenset()
result = set(sets[0])