Merge pull request #3748 from lonvia/airports

Improve finding airports by their codes
This commit is contained in:
Sarah Hoffmann
2025-06-02 14:39:02 +02:00
committed by GitHub
2 changed files with 22 additions and 19 deletions

View File

@@ -332,7 +332,7 @@ module.NAME_TAGS.core = {main = {'name', 'name:*',
} }
module.NAME_TAGS.address = {house = {'addr:housename'}} module.NAME_TAGS.address = {house = {'addr:housename'}}
module.NAME_TAGS.poi = group_merge({main = {'brand'}, module.NAME_TAGS.poi = group_merge({main = {'brand'},
extra = {'iata', 'icao'}}, extra = {'iata', 'icao', 'faa'}},
module.NAME_TAGS.core) module.NAME_TAGS.core)
-- Address tagging -- Address tagging

View File

@@ -118,17 +118,20 @@ class ForwardGeocoder:
""" Remove badly matching results, sort by ranking and """ Remove badly matching results, sort by ranking and
limit to the configured number of results. limit to the configured number of results.
""" """
if results: results.sort(key=lambda r: (r.ranking, 0 if r.bbox is None else -r.bbox.area))
results.sort(key=lambda r: (r.ranking, 0 if r.bbox is None else -r.bbox.area))
min_rank = results[0].rank_search
min_ranking = results[0].ranking
results = SearchResults(r for r in results
if (r.ranking + 0.03 * (r.rank_search - min_rank)
< min_ranking + 0.5))
results = SearchResults(results[:self.limit]) final = SearchResults()
min_rank = results[0].rank_search
min_ranking = results[0].ranking
return results for r in results:
if r.ranking + 0.03 * (r.rank_search - min_rank) < min_ranking + 0.5:
final.append(r)
min_rank = min(r.rank_search, min_rank)
if len(final) == self.limit:
break
return final
def rerank_by_query(self, query: QueryStruct, results: SearchResults) -> None: def rerank_by_query(self, query: QueryStruct, results: SearchResults) -> None:
""" Adjust the accuracy of the localized result according to how well """ Adjust the accuracy of the localized result according to how well
@@ -153,17 +156,16 @@ class ForwardGeocoder:
if not words: if not words:
continue continue
for qword in qwords: for qword in qwords:
wdist = max(difflib.SequenceMatcher(a=qword, b=w).quick_ratio() for w in words) # only add distance penalty if there is no perfect match
if wdist < 0.5: if qword not in words:
distance += len(qword) wdist = max(difflib.SequenceMatcher(a=qword, b=w).quick_ratio() for w in words)
else: distance += len(qword) if wdist < 0.4 else 1
distance += (1.0 - wdist) * len(qword)
# Compensate for the fact that country names do not get a # Compensate for the fact that country names do not get a
# match penalty yet by the tokenizer. # match penalty yet by the tokenizer.
# Temporary hack that needs to be removed! # Temporary hack that needs to be removed!
if result.rank_address == 4: if result.rank_address == 4:
distance *= 2 distance *= 2
result.accuracy += distance * 0.4 / sum(len(w) for w in qwords) result.accuracy += distance * 0.3 / sum(len(w) for w in qwords)
async def lookup_pois(self, categories: List[Tuple[str, str]], async def lookup_pois(self, categories: List[Tuple[str, str]],
phrases: List[Phrase]) -> SearchResults: phrases: List[Phrase]) -> SearchResults:
@@ -211,9 +213,10 @@ class ForwardGeocoder:
results = self.pre_filter_results(results) results = self.pre_filter_results(results)
await add_result_details(self.conn, results, self.params) await add_result_details(self.conn, results, self.params)
log().result_dump('Preliminary Results', ((r.accuracy, r) for r in results)) log().result_dump('Preliminary Results', ((r.accuracy, r) for r in results))
self.rerank_by_query(query, results) if len(results) > 1:
log().result_dump('Results after reranking', ((r.accuracy, r) for r in results)) self.rerank_by_query(query, results)
results = self.sort_and_cut_results(results) log().result_dump('Results after reranking', ((r.accuracy, r) for r in results))
results = self.sort_and_cut_results(results)
log().result_dump('Final Results', ((r.accuracy, r) for r in results)) log().result_dump('Final Results', ((r.accuracy, r) for r in results))
return results return results