]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/api/search/geocoder.py
Merge pull request #3292 from lonvia/faster-country-search
[nominatim.git] / nominatim / api / search / geocoder.py
index 7ff3ed08af9dcfa23c8072d4d57152a253930007..6b58c9457c16598ea8c735f8bcdb5d55a820febf 100644 (file)
@@ -64,7 +64,7 @@ class ForwardGeocoder:
                     log().table_dump('Searches for assignment',
                                      _dump_searches(searches, query, num_searches))
                 num_searches = len(searches)
                     log().table_dump('Searches for assignment',
                                      _dump_searches(searches, query, num_searches))
                 num_searches = len(searches)
-            searches.sort(key=lambda s: s.penalty)
+            searches.sort(key=lambda s: (s.penalty, s.SEARCH_PRIO))
 
         return query, searches
 
 
         return query, searches
 
@@ -79,12 +79,13 @@ class ForwardGeocoder:
 
         end_time = dt.datetime.now() + self.timeout
 
 
         end_time = dt.datetime.now() + self.timeout
 
-        min_ranking = 1000.0
+        min_ranking = searches[0].penalty + 2.0
         prev_penalty = 0.0
         for i, search in enumerate(searches):
             if search.penalty > prev_penalty and (search.penalty > min_ranking or i > 20):
                 break
             log().table_dump(f"{i + 1}. Search", _dump_searches([search], query))
         prev_penalty = 0.0
         for i, search in enumerate(searches):
             if search.penalty > prev_penalty and (search.penalty > min_ranking or i > 20):
                 break
             log().table_dump(f"{i + 1}. Search", _dump_searches([search], query))
+            log().var_dump('Params', self.params)
             lookup_results = await search.lookup(self.conn, self.params)
             for result in lookup_results:
                 rhash = (result.source_table, result.place_id,
             lookup_results = await search.lookup(self.conn, self.params)
             for result in lookup_results:
                 rhash = (result.source_table, result.place_id,
@@ -94,7 +95,7 @@ class ForwardGeocoder:
                     prevresult.accuracy = min(prevresult.accuracy, result.accuracy)
                 else:
                     results[rhash] = result
                     prevresult.accuracy = min(prevresult.accuracy, result.accuracy)
                 else:
                     results[rhash] = result
-                min_ranking = min(min_ranking, result.ranking + 0.5, search.penalty + 0.3)
+                min_ranking = min(min_ranking, result.accuracy * 1.2)
             log().result_dump('Results', ((r.accuracy, r) for r in lookup_results))
             prev_penalty = search.penalty
             if dt.datetime.now() >= end_time:
             log().result_dump('Results', ((r.accuracy, r) for r in lookup_results))
             prev_penalty = search.penalty
             if dt.datetime.now() >= end_time:
@@ -134,7 +135,10 @@ class ForwardGeocoder:
             return
 
         for result in results:
             return
 
         for result in results:
-            if not result.display_name:
+            # Negative importance indicates ordering by distance, which is
+            # more important than word matching.
+            if not result.display_name\
+               or (result.importance is not None and result.importance < 0):
                 continue
             distance = 0.0
             norm = self.query_analyzer.normalize_text(result.display_name)
                 continue
             distance = 0.0
             norm = self.query_analyzer.normalize_text(result.display_name)