1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Implementation of the acutal database accesses for forward search.
12 from nominatim.api.connection import SearchConnection
13 from nominatim.api.types import SearchDetails
14 import nominatim.api.results as nres
15 from nominatim.api.search.db_search_fields import SearchData, WeightedCategories
17 class AbstractSearch(abc.ABC):
18 """ Encapuslation of a single lookup in the database.
21 def __init__(self, penalty: float) -> None:
22 self.penalty = penalty
25 async def lookup(self, conn: SearchConnection,
26 details: SearchDetails) -> nres.SearchResults:
27 """ Find results for the search in the database.
31 class NearSearch(AbstractSearch):
32 """ Category search of a place type near the result of another search.
34 def __init__(self, penalty: float, categories: WeightedCategories,
35 search: AbstractSearch) -> None:
36 super().__init__(penalty)
38 self.categories = categories
41 async def lookup(self, conn: SearchConnection,
42 details: SearchDetails) -> nres.SearchResults:
43 """ Find results for the search in the database.
45 return nres.SearchResults([])
48 class PoiSearch(AbstractSearch):
49 """ Category search in a geographic area.
51 def __init__(self, sdata: SearchData) -> None:
52 super().__init__(sdata.penalty)
53 self.categories = sdata.qualifiers
54 self.countries = sdata.countries
57 async def lookup(self, conn: SearchConnection,
58 details: SearchDetails) -> nres.SearchResults:
59 """ Find results for the search in the database.
61 return nres.SearchResults([])
64 class CountrySearch(AbstractSearch):
65 """ Search for a country name or country code.
67 def __init__(self, sdata: SearchData) -> None:
68 super().__init__(sdata.penalty)
69 self.countries = sdata.countries
72 async def lookup(self, conn: SearchConnection,
73 details: SearchDetails) -> nres.SearchResults:
74 """ Find results for the search in the database.
76 return nres.SearchResults([])
79 class PostcodeSearch(AbstractSearch):
80 """ Search for a postcode.
82 def __init__(self, extra_penalty: float, sdata: SearchData) -> None:
83 super().__init__(sdata.penalty + extra_penalty)
84 self.countries = sdata.countries
85 self.postcodes = sdata.postcodes
86 self.lookups = sdata.lookups
87 self.rankings = sdata.rankings
90 async def lookup(self, conn: SearchConnection,
91 details: SearchDetails) -> nres.SearchResults:
92 """ Find results for the search in the database.
94 return nres.SearchResults([])
97 class PlaceSearch(AbstractSearch):
98 """ Generic search for an address or named place.
100 def __init__(self, extra_penalty: float, sdata: SearchData, expected_count: int) -> None:
101 super().__init__(sdata.penalty + extra_penalty)
102 self.countries = sdata.countries
103 self.postcodes = sdata.postcodes
104 self.housenumbers = sdata.housenumbers
105 self.qualifiers = sdata.qualifiers
106 self.lookups = sdata.lookups
107 self.rankings = sdata.rankings
108 self.expected_count = expected_count
111 async def lookup(self, conn: SearchConnection,
112 details: SearchDetails) -> nres.SearchResults:
113 """ Find results for the search in the database.
115 return nres.SearchResults([])