Check near-year candidates before the unique exact-title fallback in best_match
This commit is contained in:
@@ -983,10 +983,6 @@ def best_match(media_type, results, year, query=None):
|
|||||||
if not query_norm:
|
if not query_norm:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
exact_matches = [r for r in results if is_exact_title(r)]
|
|
||||||
if len(exact_matches) == 1:
|
|
||||||
return exact_matches[0]
|
|
||||||
|
|
||||||
def near_title_similarity(r):
|
def near_title_similarity(r):
|
||||||
return difflib.SequenceMatcher(
|
return difflib.SequenceMatcher(
|
||||||
None, query_norm, clean_and_squeeze(result_title(media_type, r) or "").lower()
|
None, query_norm, clean_and_squeeze(result_title(media_type, r) or "").lower()
|
||||||
@@ -1001,6 +997,11 @@ def best_match(media_type, results, year, query=None):
|
|||||||
threshold = YEAR_MATCH_MIN_SIMILARITY if len(near_year_matches) == 1 else NEAR_YEAR_MATCH_MIN_SIMILARITY
|
threshold = YEAR_MATCH_MIN_SIMILARITY if len(near_year_matches) == 1 else NEAR_YEAR_MATCH_MIN_SIMILARITY
|
||||||
if near_title_similarity(best) >= threshold:
|
if near_title_similarity(best) >= threshold:
|
||||||
return best
|
return best
|
||||||
|
|
||||||
|
exact_matches = [r for r in results if is_exact_title(r)]
|
||||||
|
if len(exact_matches) == 1:
|
||||||
|
return exact_matches[0]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
if not query_norm:
|
if not query_norm:
|
||||||
return year_matches[0]
|
return year_matches[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user