Skip to content

Commit 2c0a694

Browse files
author
hka
committed
Add initial search documentation for solr + fulltext search
1 parent ff3a3ce commit 2c0a694

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed
15.2 KB
Loading
14.3 KB
Loading
21.7 KB
Loading

src/topics/Search.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,145 @@ Note: The `qwc2-demo-app` (also used by the `qwc-map-viewer-demo` docker image)
118118

119119
## Configuring the fulltext search service <a name="fulltext-search"></a>
120120

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_NAME",
219+
"filter_word": "OPTIONAL_SEARCH_FILTER",
220+
"table_name": "SCHEMA.SEARCH_TABLE_NAME",
221+
"geometry_column": "GEOMETRY_FIELD",
222+
"search_id_col": "PRIMARY_KEY"
223+
}
224+
```
225+
226+
The `filter_word` field can be specified to activate / deactivate searches,
227+
if you have configure multiple searches for one map.
228+
Normally `filter_word` is left empty (`""`) which results in the search always
229+
being active.
230+
But if specified (e.g. `"house_no"` then the fulltext search will only use
231+
the configured search, if the user prefixes his search choise with "house_no:".
232+
233+
### Activate search for a map
234+
235+
In the last step, you only have to activate the search for a specific topic
236+
and give the users the necessary rights in the Admin GUI.
237+
238+
1. Add the following to a theme item in the `themesConfig`:
239+
240+
```json
241+
"searchProviders": [
242+
{
243+
"provider": "solr",
244+
"default": [],
245+
"layers": {
246+
"QGIS_LAYER": "SEARCH_NAME"
247+
}
248+
}
249+
]
250+
```
251+
252+
2. Create a new resource in the Admin GUI
253+
254+
![Create resource](../images/create_solr_search_facet_resource.png?style=centerme)
255+
256+
3. Add permissions on the newly created resource
257+
258+
![Add permission](../images/add_solr_search_facet_permission.png?style=centerme)
259+
260+
4. Re-generate the services configurations with the `Generate service configuration` button
261+
262+
![Generate service configurations](../images/generate_service_configurations.png?style=centerme)

0 commit comments

Comments
 (0)