2 Mix-ins that provide the actual commands for the indexer for various indexing
5 # pylint: disable=C0111
8 """ Returns SQL commands for indexing one rank within the placex table.
11 def __init__(self, rank):
15 return "rank {}".format(self.rank)
17 def sql_count_objects(self):
18 return """SELECT count(*) FROM placex
19 WHERE rank_address = {} and indexed_status > 0
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)
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)))
34 """ Returns SQL commands for indexing the administrative boundaries
38 def __init__(self, rank):
42 return "boundaries rank {}".format(self.rank)
44 def sql_count_objects(self):
45 return """SELECT count(*) FROM placex
46 WHERE indexed_status > 0
48 AND class = 'boundary' and type = 'administrative'
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
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)))
64 class InterpolationRunner:
65 """ Returns SQL commands for indexing the address interpolation table
66 location_property_osmline.
71 return "interpolation lines (location_property_osmline)"
74 def sql_count_objects():
75 return """SELECT count(*) FROM location_property_osmline
76 WHERE indexed_status > 0"""
79 def sql_get_objects():
80 return """SELECT place_id FROM location_property_osmline
81 WHERE indexed_status > 0
82 ORDER BY geometry_sector"""
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)))
92 """ Provides the SQL commands for indexing the location_postcode table.
97 return "postcodes (location_postcode)"
100 def sql_count_objects():
101 return 'SELECT count(*) FROM location_postcode WHERE indexed_status > 0'
104 def sql_get_objects():
105 return """SELECT place_id FROM location_postcode
106 WHERE indexed_status > 0
107 ORDER BY country_code, postcode"""
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)))