]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/indexer/runners.py
pylint: disable check too-few-public-methods
[nominatim.git] / nominatim / indexer / runners.py
1 """
2 Mix-ins that provide the actual commands for the indexer for various indexing
3 tasks.
4 """
5 # pylint: disable=C0111
6
7 class RankRunner:
8     """ Returns SQL commands for indexing one rank within the placex table.
9     """
10
11     def __init__(self, rank):
12         self.rank = rank
13
14     def name(self):
15         return "rank {}".format(self.rank)
16
17     def sql_count_objects(self):
18         return """SELECT count(*) FROM placex
19                   WHERE rank_address = {} and indexed_status > 0
20                """.format(self.rank)
21
22     def sql_get_objects(self):
23         return """SELECT place_id FROM placex
24                   WHERE indexed_status > 0 and rank_address = {}
25                   ORDER BY geometry_sector""".format(self.rank)
26
27     @staticmethod
28     def sql_index_place(ids):
29         return "UPDATE placex SET indexed_status = 0 WHERE place_id IN ({})"\
30                .format(','.join((str(i) for i in ids)))
31
32
33 class BoundaryRunner:
34     """ Returns SQL commands for indexing the administrative boundaries
35         of a certain rank.
36     """
37
38     def __init__(self, rank):
39         self.rank = rank
40
41     def name(self):
42         return "boundaries rank {}".format(self.rank)
43
44     def sql_count_objects(self):
45         return """SELECT count(*) FROM placex
46                   WHERE indexed_status > 0
47                     AND rank_search = {}
48                     AND class = 'boundary' and type = 'administrative'
49                """.format(self.rank)
50
51     def sql_get_objects(self):
52         return """SELECT place_id FROM placex
53                   WHERE indexed_status > 0 and rank_search = {}
54                         and class = 'boundary' and type = 'administrative'
55                   ORDER BY partition, admin_level
56                """.format(self.rank)
57
58     @staticmethod
59     def sql_index_place(ids):
60         return "UPDATE placex SET indexed_status = 0 WHERE place_id IN ({})"\
61                .format(','.join((str(i) for i in ids)))
62
63
64 class InterpolationRunner:
65     """ Returns SQL commands for indexing the address interpolation table
66         location_property_osmline.
67     """
68
69     @staticmethod
70     def name():
71         return "interpolation lines (location_property_osmline)"
72
73     @staticmethod
74     def sql_count_objects():
75         return """SELECT count(*) FROM location_property_osmline
76                   WHERE indexed_status > 0"""
77
78     @staticmethod
79     def sql_get_objects():
80         return """SELECT place_id FROM location_property_osmline
81                   WHERE indexed_status > 0
82                   ORDER BY geometry_sector"""
83
84     @staticmethod
85     def sql_index_place(ids):
86         return """UPDATE location_property_osmline
87                   SET indexed_status = 0 WHERE place_id IN ({})
88                """.format(','.join((str(i) for i in ids)))
89
90
91 class PostcodeRunner:
92     """ Provides the SQL commands for indexing the location_postcode table.
93     """
94
95     @staticmethod
96     def name():
97         return "postcodes (location_postcode)"
98
99     @staticmethod
100     def sql_count_objects():
101         return 'SELECT count(*) FROM location_postcode WHERE indexed_status > 0'
102
103     @staticmethod
104     def sql_get_objects():
105         return """SELECT place_id FROM location_postcode
106                   WHERE indexed_status > 0
107                   ORDER BY country_code, postcode"""
108
109     @staticmethod
110     def sql_index_place(ids):
111         return """UPDATE location_postcode SET indexed_status = 0
112                   WHERE place_id IN ({})
113                """.format(','.join((str(i) for i in ids)))