@@ -118,4 +118,162 @@ Note: The `qwc2-demo-app` (also used by the `qwc-map-viewer-demo` docker image)
118
118
119
119
## Configuring the fulltext search service <a name =" fulltext-search " ></a >
120
120
121
- For more information on the full-text search provider, see [ qwc-fulltext-search-service] ( https://github.com/qwc-services/qwc-fulltext-search-service ) .
121
+ ### Solr configuration
122
+
123
+ Before the fulltext search service can be configured,
124
+ a new solr configuration file must be created.
125
+ This file must be created in ` volumes/solr/configsets/gdi/conf/ ` .
126
+ The name of the file can be chosen freely.
127
+ Here is an example XML file:
128
+
129
+ ``` xml
130
+ <dataConfig >
131
+ <dataSource
132
+ driver =" org.postgresql.Driver"
133
+ url =" jdbc:postgresql://{DB_HOST}:{DB_PORT}/{DB_NAME}"
134
+ user =" {DB_USER}"
135
+ password =" {DB_PASSWORD}"
136
+ />
137
+ <document >
138
+ <entity name =" {SEARCH_NAME}" query ="
139
+ WITH index_base AS (
140
+ /* ==== Base query for search index ==== */
141
+ SELECT
142
+ '{SEARCH_NAME}'::text AS subclass,
143
+ {PRIMARY_KEY} AS id_in_class,
144
+ '{PRIMARY_KEY}' AS id_name,
145
+ '{SEARCH_FIELD_DATA_TYPE}:n' AS id_type,
146
+ {DISPLAYTEXT} AS displaytext,
147
+ {SEARCH_FIELD_1} AS search_part_1,
148
+ {GEOMETRY_FIELD} AS geom
149
+ FROM {SCHEMA}.{SEARCH_TABLE_NAME}
150
+ /* ===================================== */
151
+ )
152
+ SELECT
153
+ (array_to_json(array_append(ARRAY[subclass::text], id_in_class::text)))::text AS id,
154
+ displaytext AS display,
155
+ search_part_1 AS search_1_stem,
156
+ search_part_1 AS sort,
157
+ subclass AS facet,
158
+ 'default' AS tenant,
159
+ (array_to_json(array_append(ARRAY[id_name::text], id_type::text)))::text AS idfield_meta,
160
+ (st_asgeojson(st_envelope(geom), 0, 1)::json -> 'bbox')::text AS bbox
161
+ FROM index_base" >
162
+ </entity >
163
+ </document >
164
+ </dataConfig >
165
+ ```
166
+
167
+ The next table shows how the values, that are surrounded by ` {} ` , need to be defined.
168
+
169
+ | ** Name** | ** Definition** | ** Example** |
170
+ | --------------------------| -----------------------------------------------------------------------------------| ------------------|
171
+ | ` DB_HOST ` | Database hostname | ` qwc-postgis ` |
172
+ | ` DB_NAME ` | Database name | ` qwc_demo ` |
173
+ | ` DB_PORT ` | Database port number | ` 5432 ` |
174
+ | ` DB_USER ` | Database username | ` qwc_service ` |
175
+ | ` DB_PASSWORD ` | Password for the specified database user | ` qwc_service ` |
176
+ | ` SEARCH_NAME ` | Name of the search | ` fluesse_search ` |
177
+ | ` PRIMARY_KEY ` | Primary key name of the table that is used in the search query | ` ogc_fid ` |
178
+ | ` SEARCH_FIELD_DATA_TYPE ` | Search field data type | ` str ` |
179
+ | ` DISPLAYTEXT ` | Displaytext that will be shown by the QWC2 when a match was found | ` name_long ` |
180
+ | ` SEARCH_FIELD_1 ` | Table field that will be used by the search | ` name_long ` |
181
+ | ` GEOMETRY_FIELD ` | Name of the geometry column of the search table | ` wkb_geometry ` |
182
+ | ` SCHEMA ` | Search table schema | ` qwc_geodb ` |
183
+ | ` SEARCH_TABLE_NAME ` | Search table name | ` fluesse ` |
184
+
185
+ * IMPORTANT* :
186
+ In the case of several searches sharing the same database connection,
187
+ all searche queries can be written to the same XML file. Each search
188
+ corresponds to exactly one <entity > tag in the XML file.
189
+
190
+ After the configuration file has been created, the search must be registered in ` solr ` .
191
+ In the ` volumes/solr/configsets/gdi/conf/solrconfig.xml ` file you have to look for
192
+ ` <!-- SearchHandler ` and add the following configuration
193
+
194
+ ``` xml
195
+ <requestHandler name =" /SEARCH_NAME" class =" solr.DataImportHandler" >
196
+ <lst name =" defaults" >
197
+ <str name =" config" >NAME_OF_THE_CONFIGURATION_FILE.xml</str >
198
+ </lst >
199
+ </requestHandler >
200
+ ```
201
+
202
+ At last, the ` solr ` index has to be generated:
203
+
204
+ ```
205
+ rm -rf volumes/solr/data/*
206
+ docker compose restart qwc-solr
207
+ curl 'http://localhost:8983/solr/gdi/SEARCH_NAME?command=full-import'
208
+ ```
209
+
210
+ ### Configure fulltext service
211
+
212
+ The configuration of the fulltext search service can be found in ` tenantConfig.json ` .
213
+ Search the ` services ` list for the JSON object that has ` search ` as its name.
214
+ Then add a new facet to the facets list. An example entry could be:
215
+
216
+ ``` json
217
+ {
218
+ "name" : " search" ,
219
+ "config" : {
220
+ "solr_service_url" : " http://qwc-solr:8983/solr/gdi/select" ,
221
+ "search_result_limit" : 50 ,
222
+ "db_url" : " postgresql:///?service=qwc_geodb"
223
+ },
224
+ "resources" : {
225
+ "facets" : [
226
+ {
227
+ "name" : " SEARCH_NAME" ,
228
+ "filter_word" : " OPTIONAL_SEARCH_FILTER" ,
229
+ "table_name" : " SCHEMA.SEARCH_TABLE_NAME" ,
230
+ "geometry_column" : " GEOMETRY_FIELD" ,
231
+ "search_id_col" : " PRIMARY_KEY"
232
+ }
233
+ ]
234
+ }
235
+ }
236
+ ```
237
+
238
+ The ` filter_word ` field can be specified to activate / deactivate searches,
239
+ if you have configure multiple searches for one theme.
240
+ Normally ` filter_word ` is left empty (` "" ` ) which results in the search always
241
+ being active.
242
+ But if specified (e.g. ` "house_no" ` then the fulltext search will only use
243
+ the configured search, if the user prefixes his search choise with "house_no:".
244
+
245
+ ### Activate search for a map
246
+
247
+ In the last step, you only have to activate the search for a specific topic
248
+ and give the users the necessary rights in the Admin GUI.
249
+
250
+ 1 . Add the following to a theme item in the ` themesConfig ` :
251
+
252
+ ``` json
253
+ "searchProviders" : [
254
+ {
255
+ "provider" : " solr" ,
256
+ "default" : [],
257
+ "layers" : {
258
+ "QGIS_LAYER" : " SEARCH_NAME"
259
+ }
260
+ }
261
+ ]
262
+ ```
263
+
264
+ When activating a search to a theme, you can either:
265
+
266
+ * Add the search name to the ` default ` list, where it is always active
267
+ * Add the search name to the ` layers ` object, where it is only active if the QGIS layer called ` QGIS_LAYER ` is present on the map
268
+
269
+ 2 . Create a new resource in the Admin GUI
270
+
271
+ ![ Create resource] ( ../images/create_solr_search_facet_resource.png?style=centerme )
272
+
273
+ 3 . Add permissions on the newly created resource
274
+
275
+ ![ Add permission] ( ../images/add_solr_search_facet_permission.png?style=centerme )
276
+
277
+ 4 . Re-generate the services configurations with the ` Generate service configuration ` button
278
+
279
+ ![ Generate service configurations] ( ../images/generate_service_configurations.png?style=centerme )
0 commit comments