@@ -2,6 +2,7 @@ use crate::addresses::find_address;
2
2
use crate :: addresses:: iter_admins;
3
3
use crate :: langs:: COUNTRIES_LANGS ;
4
4
use crate :: lazy_es:: LazyEs ;
5
+ use itertools:: Itertools ;
5
6
use mimir:: objects:: I18nProperties ;
6
7
use mimir:: Poi ;
7
8
use mimir:: Property ;
@@ -16,6 +17,8 @@ use std::collections::HashMap;
16
17
17
18
use once_cell:: sync:: Lazy ;
18
19
20
+ const TAGS_TO_INDEX_AS_POI_TYPE_NAME : & [ & str ] = & [ "cuisine" ] ;
21
+
19
22
static NON_SEARCHABLE_ITEMS : Lazy < BTreeSet < ( String , String ) > > = Lazy :: new ( || {
20
23
[
21
24
/*
@@ -69,9 +72,9 @@ impl IndexedPoi {
69
72
let mapping_key: String = row. get ( "mapping_key" ) ;
70
73
let class: String = row. get ( "class" ) ;
71
74
let subclass = row. get :: < _ , Option < String > > ( "subclass" ) . unwrap_or_default ( ) ;
72
-
73
- let poi_type_id : String = format ! ( "class_{}:subclass_{}" , class , subclass ) ;
74
- let poi_type_name : String = format ! ( "class_{} subclass_{}" , class , subclass ) ;
75
+ let tags = row
76
+ . get :: < _ , Option < HashMap < _ , _ > > > ( "tags" )
77
+ . unwrap_or_default ( ) ;
75
78
76
79
let weight = row. get :: < _ , Option < f64 > > ( "weight" ) . unwrap_or ( 0. ) ;
77
80
@@ -94,7 +97,9 @@ impl IndexedPoi {
94
97
return None ;
95
98
}
96
99
97
- let row_properties = properties_from_row ( & row) . unwrap_or_else ( |_| vec ! [ ] ) ;
100
+ let poi_type_id = format ! ( "class_{}:subclass_{}" , class, subclass) ;
101
+ let poi_type_text = build_poi_type_text ( & class, & subclass, & tags) ;
102
+ let row_properties = properties_from_tags ( tags) ;
98
103
let names = build_names ( langs, & row_properties) ;
99
104
let properties = build_poi_properties ( & row, row_properties) ;
100
105
@@ -107,7 +112,7 @@ impl IndexedPoi {
107
112
approx_coord : Some ( poi_coord. into ( ) ) ,
108
113
poi_type : PoiType {
109
114
id : poi_type_id,
110
- name : poi_type_name ,
115
+ name : poi_type_text ,
111
116
} ,
112
117
label : "" . into ( ) ,
113
118
properties,
@@ -217,23 +222,51 @@ impl IndexedPoi {
217
222
}
218
223
}
219
224
220
- fn properties_from_row ( row : & Row ) -> Result < Vec < Property > , String > {
221
- let properties = row
222
- . try_get :: < _ , Option < HashMap < _ , _ > > > ( "tags" )
223
- . map_err ( |err| {
224
- let id: String = row. get ( "id" ) ;
225
- warn ! ( "Unable to get tags from row '{}': {:?}" , id, err) ;
226
- err. to_string ( )
227
- } ) ?
228
- . unwrap_or_else ( HashMap :: new)
229
- . into_iter ( )
225
+ fn properties_from_tags ( tags : HashMap < String , Option < String > > ) -> Vec < Property > {
226
+ tags. into_iter ( )
230
227
. map ( |( k, v) | Property {
231
228
key : k,
232
229
value : v. unwrap_or_else ( || "" . to_string ( ) ) ,
233
230
} )
234
- . collect :: < Vec < Property > > ( ) ;
231
+ . collect ( )
232
+ }
233
+
234
+ fn build_poi_type_text (
235
+ class : & str ,
236
+ subclass : & str ,
237
+ tags : & HashMap < String , Option < String > > ,
238
+ ) -> String {
239
+ /*
240
+ To index certain tags (in addition to class and subclass), we use
241
+ the field "poi_type.name" in a convoluted way.
242
+ In the POI mapping configuration defined in mimirsbrunn, this field in indexed
243
+ using a "word" analyzer.
235
244
236
- Ok ( properties)
245
+ So each key/value must be defined as a word in this field, using the following format:
246
+ * "class_<class_name>"
247
+ * "subclass_<subclass_name>"
248
+ * "<tag_key>:<tag_value>" (e.g "cuisine:japanese")
249
+
250
+ When the tag contains multiple values (separated by ";"), these values are split
251
+ and indexed as distinct tag values.
252
+ */
253
+ std:: array:: IntoIter :: new ( [ format ! ( "class_{}" , class) , format ! ( "subclass_{}" , subclass) ] )
254
+ . chain (
255
+ TAGS_TO_INDEX_AS_POI_TYPE_NAME
256
+ . iter ( )
257
+ . map ( |tag| {
258
+ let values = tags. get ( * tag) . unwrap_or ( & None ) . clone ( ) . unwrap_or_default ( ) ;
259
+ if values. is_empty ( ) {
260
+ return vec ! [ ] ;
261
+ }
262
+ values
263
+ . split ( ';' )
264
+ . map ( |v| format ! ( "{}:{}" , tag, v) )
265
+ . collect :: < Vec < _ > > ( )
266
+ } )
267
+ . flatten ( ) ,
268
+ )
269
+ . join ( " " )
237
270
}
238
271
239
272
fn build_poi_properties ( row : & Row , mut properties : Vec < Property > ) -> Vec < Property > {
0 commit comments