Skip to content

Commit 116517c

Browse files
committed
Document trgm_feature_query_template and trgm_layer_query_template
1 parent d8b6555 commit 116517c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/topics/Search.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ A facet references a searchable dataset. The configuration of the fulltext searc
247247
"db_url": "postgresql:///?service=qwc_geodb",
248248
// trgm specific configuration, see below
249249
"trgm_feature_query": "<see below>",
250+
"trgm_feature_query_template": "<see below>",
250251
"trgm_layer_query": "<see below>",
252+
"trgm_layer_query_template": "<see below>",
251253
"trgm_similarity_threshold": "0.3"
252254
// solr specific configuration, see below
253255
"solr_service_url": "http://localhost:8983/solr/gdi/select",
@@ -313,6 +315,18 @@ The `trgm_layer_query` must return the following fields:
313315

314316
*Note*: The layer query relies on an additional service, configured as `dataproductServiceUrl` in the viewer `config.json`, which resolves the `dataproduct_id` to a QWC theme sublayer object, like the [`sogis-dataproduct-service`](https://github.com/qwc-services/sogis-dataproduct-service).
315317

318+
In alternative to specifying `trgm_feature_query` and/or `trgm_layer_query`, you can set `trgm_feature_query_template` and/or `trgm_layer_query_template` to a [Jinja template string](https://jinja.palletsprojects.com/en/stable/templates/) which generates the final SQL query. The following variables are available in the template string:
319+
320+
* `searchtext`: the full search text, as a string
321+
* `words`: the single words of the search text, as an array
322+
* `facets`: the permitted search facets, as an array
323+
324+
Example for `trgm_feature_query_template` to generate an "unrolled" query for each word in the searchtext:
325+
326+
SELECT display, facet_id, id_field_name, feature_id, bbox, srid FROM public.search_index
327+
WHERE {% for word in words %} searchterms ILIKE '%' || '{{ word }}' || '%' {% if not loop.last %} AND {% endif %} {% endfor %}
328+
ORDER BY {% for word in words %} similarity(searchterms, '{{ word }}') {% if not loop.last %} + {% endif %} {% endfor %} DESC
329+
316330
*Note*: Set `FLASK_DEBUG=1` as environment variable for the search service to see additional logging information.
317331

318332
### Fulltext search with Solr backend

0 commit comments

Comments
 (0)