]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/api/results.py
implement actual database searches
[nominatim.git] / nominatim / api / results.py
index 56243e8d7672121c7cf5471f46c19f09aa12a799..1c313398e0d94b88ec68e32e16f8de6da06d86d7 100644 (file)
@@ -179,6 +179,15 @@ class SearchResult(BaseResult):
     """ A search result for forward geocoding.
     """
     bbox: Optional[Bbox] = None
+    accuracy: float = 0.0
+
+
+    @property
+    def ranking(self) -> float:
+        """ Return the ranking, a combined measure of accuracy and importance.
+        """
+        return (self.accuracy if self.accuracy is not None else 1) \
+               - self.calculated_importance()
 
 
 class SearchResults(List[SearchResult]):
@@ -306,6 +315,23 @@ def create_from_postcode_row(row: Optional[SaRow],
                       geometry=_filter_geometries(row))
 
 
+def create_from_country_row(row: Optional[SaRow],
+                        class_type: Type[BaseResultT]) -> Optional[BaseResultT]:
+    """ Construct a new result and add the data from the result row
+        from the fallback country tables. 'class_type' defines
+        the type of result to return. Returns None if the row is None.
+    """
+    if row is None:
+        return None
+
+    return class_type(source_table=SourceTable.COUNTRY,
+                      category=('place', 'country'),
+                      centroid=Point.from_wkb(row.centroid.data),
+                      names=row.name,
+                      rank_address=4, rank_search=4,
+                      country_code=row.country_code)
+
+
 async def add_result_details(conn: SearchConnection, result: BaseResult,
                              details: LookupDetails) -> None:
     """ Retrieve more details from the database according to the