Skip to content

Commit e1cbdc9

Browse files
committed
Document search provider changes
1 parent c8aeb14 commit e1cbdc9

File tree

3 files changed

+135
-48
lines changed

3 files changed

+135
-48
lines changed

src/release_notes/QWC2UpgradeNotes.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,68 @@ This document describes incompatibilites and other aspects which QWC2 applicatio
44

55
When updating the `qwc2` submodule, run `yarn install` to ensure the dependencies are up to date!
66

7+
Update to qwc2 submodule revision [e39dbde](https://github.com/qgis/qwc2/tree/e39dbde) (26.11.2024)
8+
---------------------------------------------------------------------------------------------------
9+
10+
**Search providers rework**
11+
The search providers from `qwc2-demo-app/js/searchProviders.js` have been moved to the core in `qwc2/utils/SearchProviders.js`.
12+
13+
To define custom search providers, expose them in `window.QWC2SearchProviders`, see [Search](../topics/Search.md).
14+
15+
The `SearchBox` and `Routing` plugins don't take a SearchProviders object anymore, they are internally collected from the core providers and from `window.QWC2SearchProviders`.
16+
Consequently, modify your `js/appConfig.js` as follows:
17+
18+
```
19+
- RoutingPlugin: RoutingPlugin(SearchProviders),
20+
+ RoutingPlugin: RoutingPlugin,
21+
...
22+
TopBarPlugin: TopBarPlugin({
23+
- Search: SearchBox(SearchProviders),
24+
+ Search: SearchBox,
25+
```
26+
27+
The format of the results returned by a Search Provider needs to be slightly updated to specify the result item type in the result group instead of the result item, see [Search](../topics/Search.md):
28+
29+
```js
30+
results = [
31+
{
32+
id: "<categoryid>",
33+
...
34+
type: SearchResultType.{PLACE|THEMELAYER}, // NEW
35+
items: [
36+
{
37+
id: "<item_id>",
38+
type: SearchResultType.{PLACE|THEMELAYER}, // OLD, remove this
39+
...
40+
}
41+
]
42+
}
43+
```
44+
45+
The configuration format of the fulltext search provider has also changed, to align it with the configuration format of other providers.
46+
47+
Old:
48+
49+
```json
50+
{
51+
"provider":"solr", // or "provider":"fulltext"
52+
"default": ["<facet>", "<facet>", ...],
53+
"layers": {"<layername>": "<facet>", ...}
54+
}
55+
```
56+
57+
New:
58+
59+
```json
60+
{
61+
"provider":"fulltext",
62+
"params": {
63+
"default": ["<facet>", "<facet>", ...],
64+
"layers": {"<layername>": "<facet>", ...}
65+
}
66+
}
67+
```
68+
769
Update to qwc2 submodule revision [9cb8bab](https://github.com/qgis/qwc2/tree/9cb8bab) (13.11.2024)
870
---------------------------------------------------------------------------------------------------
971

src/topics/Interfacing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following parameters can appear in the URL of the QWC2 application:
1515
- `crs`: The CRS of extent/center coordinates
1616
- `hc`: If `c` is specified and `hc` is `true` or `1`, a marker is set at `c` when starting the application. Note: requires the `StartupMarkerPlugin` plugin to be active.
1717
- `st`: The search text
18-
- `hp`, `hf`, `ht`: Startup highlight parameters used in conjunction with the `qwc-fulltext-search-service`, see below.
18+
- `hp`, `hf`: Startup highlight parameters used in conjunction with the `qwc-fulltext-search-service`, see below.
1919
- `f`: A filter configuration, see [Map filtering](./MapFilter.md).
2020
- `localConfig`: Override the name of the loaded config file, i.e. to load `myconfig.json` instead of the default `config.json`, pass `localConfig=myconfig`.
2121

@@ -44,8 +44,8 @@ The `urlPositionCrs` parameter in `config.json` determines the projection to use
4444
If a search text passed via `st` results in a unique result, the viewer automatically zooms to this result on startup. If the search result does not provide a bounding box, the `minScale` defined in the `searchOptions` of the `TopBar` configuration in `config.json` is used.
4545

4646
When using the `qwc-fulltext-search-service`, you can hightlight a feature on startup as follows:
47-
- Either specify `hp=<search product>&hf=<search filter>`
48-
- Or specify `ht=<search text>&hp=<search product>`
47+
- Either specify `hp=<facet_name>&hf=<filter_expr>`
48+
- Or specify `st=<filter_expr>&hp=<facet_name>`
4949

5050
See [Fulltext search](Search.md#fulltext-search) for more details.
5151

src/topics/Search.md

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,40 @@ QWC2 can be configured to use arbitrary custom search providers. In addition, th
66

77
Search providers can be defined as follows:
88

9-
- Built-in, defined in `js/SearchProviders.js`. This file is structured as follows:
9+
- As resource, defined in `static/assets/searchProviders.js`. This file is structured as follows:
1010
```js
11-
export const SearchProviders = {
11+
window.QWC2SearchProviders = {
1212
<providerkey1>: <ProviderDefinition1>,
1313
<providerkey2>: <ProviderDefinition2>,
1414
...
1515
};
1616
```
17-
Built-in search providers are compiled into the application bundle and avoid the need for an extra resource to be loaded on application startup. The downside is that you need to rebuild QWC2 to add/modify search providers.
17+
This script file needs to be loaded explicitly by `index.html` via
18+
```html
19+
<script type="text/javascript" src="assets/searchProviders.js" ></script>
20+
```
1821

19-
- As resource, defined in `static/assets/searchProviders.js`. This file is structured as follows:
22+
- Built-in, defined in `js/SearchProviders.js`. This file is structured as follows:
2023
```js
2124
window.QWC2SearchProviders = {
2225
<providerkey1>: <ProviderDefinition1>,
2326
<providerkey2>: <ProviderDefinition2>,
2427
...
2528
};
2629
```
27-
This script file needs to be loaded explicitly by `index.html` via
28-
```html
29-
<script type="text/javascript" src="assets/searchProviders.js" ></script>
30+
This file needs to be imported into the application, i.e. via
31+
```js
32+
import './SearchProviders.js';
3033
```
34+
in `js/appConfig.js`.
35+
36+
Built-in search providers are compiled into the application bundle and avoid the need for an extra resource to be loaded on application startup. The downside is that you need to rebuild QWC2 to add/modify search providers.
37+
3138
The format of `ProviderDefinition` is
3239
```js
3340
{
34-
label: "<human readable provider name>", // OR
35-
labelmsgid: "<translation message ID for human readable provider name>",
41+
label: "<label>", // Provider label (displayed in provider selection menu)
42+
labelmsgid: "<msgid>", // Translateable label message ID, instead of `label`
3643
onSearch: function(searchText, searchParams, callback, axios) => {
3744
const results = []; // See below
3845
/* Populate results... */
@@ -48,8 +55,16 @@ The format of `ProviderDefinition` is
4855
const crs = "EPSG:XXXX";
4956
const hidemarker = <boolean>; // Whether to suppress displaying a search marker on top of the search geometry
5057
callback({geometry: geometry, crs: crs, hidemarker: hidemarker});
58+
// or
59+
callback({feature: geojson_feature, crs: crs, hidemarker: hidemarker});
5160
},
52-
handlesGeomFilter: <boolean>; // Hint whether provider will completely filter the results on provider side and that no client-side filtering is necessary
61+
handlesGeomFilter: <boolean>, // Hint whether provider will completely filter the results on provider side and that no client-side filtering is necessary
62+
getLayerDefinition: function(resultItem, callback, axios) => {
63+
// layer definition, in the same format as a "sublayers" entry in themes.json
64+
const layer = {<layer_definition>};
65+
callback(layer);
66+
}
67+
}
5368
}
5469
```
5570
*Notes:*
@@ -60,9 +75,11 @@ The format of `ProviderDefinition` is
6075
displaycrs: "EPSG:XXXX", // Currently selected mouse coordinate display CRS
6176
mapcrs: "EPSG:XXXX", // The current map CRS
6277
lang: "<code>", // The current application language, i.e. en-US or en
63-
cfgParams: <params> // Additional parameters passed in the theme search provider configuration, see below
64-
filterBBox: <[xmin, ymîn, xmax, ymax]|null> // A filter bbox, in mapcrs, the search component may pass to the provider to narrow down the results
65-
filterPoly: <[[x0, y0], [x1, y1], ....]> // A filter polygon, in mapcrs, the search component may pass to the provider to narrow down the results
78+
cfgParams: <params>, // Additional parameters passed in the theme search provider configuration, see below
79+
limit: <number>, // Result count limit
80+
activeLayers: ["<layername>", ...], // List of active layers in the map
81+
filterBBox: [xmin, ymin, xmax, ymax]|null, // A filter bbox, in mapcrs, the search component may pass to the provider to narrow down the results
82+
filterPoly: [[x0, y0], [x1, y1], ....], // A filter polygon, in mapcrs, the search component may pass to the provider to narrow down the results
6683
}
6784
```
6885
* `axios` is passed for convenience so that providers can use the compiled-in `axios` library for network requests.
@@ -71,35 +88,42 @@ The format of `ProviderDefinition` is
7188
```js
7289
results = [
7390
{
74-
id: "<categoryid>", // Unique category ID
75-
title: "<display_title>", // Text to display as group title in the search results
76-
priority: priority_nr, // Optional: search result group priority. Groups with higher priority are displayed first in the list.
91+
id: "<categoryid>", // Unique category ID
92+
title: "<display_title>", // Text to display as group title in the search results
93+
titlemsgid: "<display_title_msgid>", // Translation message id for group title, instead of "title"
94+
resultCount: <result_count>, // Optional: true result count (i.e. not limited to the "limit" specified in searchParams).
95+
priority: priority_nr, // Optional: search result group priority. Groups with higher priority are displayed first in the list.
96+
type: SearchResultType.{PLACE|THEMELAYER}, // Specifies the type of results. Default: SearchResultType.PLACE
7797
items: [
78-
{ // Location search result:
79-
type: SearchResultType.PLACE, // Specifies that this is a location search result
80-
id: "<itemId">, // Unique item ID
81-
text: "<display text>", // Text to display as search result
82-
label: "<map marker text>", // Optional, text to show next to the position marker on the map instead of `text`
83-
x: x, // X coordinate of result
84-
y: y, // Y coordinate of result
85-
crs: crs, // CRS of result coordinates and bbox
86-
bbox: [xmin, ymin, xmax, ymax], // Bounding box of result (if non-empty, map will zoom to this extent when selecting result)
87-
geometry: <GeoJSON geometry> // Optional, result geometry. Note: geometries may also be fetched separately via getResultGeometry.
98+
// PLACE result
99+
{
100+
id: "<item_id>", // Unique item ID
101+
text: "<display_text>", // Text to display as search result
102+
label: "<map_marker_text>", // Optional, text to show next to the position marker on the map instead of `text`
103+
x: x, // X coordinate of result
104+
y: y, // Y coordinate of result
105+
crs: crs, // CRS of result coordinates and bbox. If not specified, the current map crs is assumed.
106+
bbox: [xmin, ymin, xmax, ymax], // Bounding box of result (if non-empty, map will zoom to this extent when selecting result)
107+
geometry: <GeoJSON geometry>, // Optional, result geometry. Note: geometries may also be fetched separately via getResultGeometry.
108+
thumbnail: "<thumbnail_url>", // Optional: thumbnail to display next to the search result text in the result list,
109+
externalLink: "<url>" // Optional: a url to an external resource. If specified, a info icon is displayed in the result entry to open the link.
110+
target: "<target>" // Optional: external link target, i.e. _blank or iframe
88111
},
89-
{ // Theme layer search result (advanced):
90-
type: SearchResultType.THEMELAYER, // Specifies that this is a theme layer search result
91-
id: "<itemId">, // Unique item ID
92-
text: "<display text>", // Text to display as search result
93-
layer: {<Layer definition>} // Layer definition, in the same format as a "sublayers" entry in themes.json.
112+
// THEMELAYER result
113+
{
114+
id: "<item_id>", // Unique item ID
115+
text: "<display_text>", // Text to display as search result
116+
layer: {<layer_definition>} // Optional: layer definition, in the same format as a "sublayers" entry in themes.json. Layer definitions may also be fetched separately via getLayerDefinition.
117+
info: <bool>, // Optional: Whether to display a info icon in the result list. The info is read from layer.abstract. If layer is not specified, the layer is fecthed via getLayerDefinition.
118+
thumbnail: "<thumbnail_url>", // Optional: thumbnail to display next to the search result text in the result list,
119+
sublayers: [{<sublayer>}, ...] // Optional: list of sublayers, in the format {id: "<item_id>", text: "<display_text>", has_info: <bool>, etc..}
94120
}
95121
]
96-
},
97-
{
98-
...
99122
}
100123
]
101124
```
102-
Consult [js/SearchProviders.js](https://github.com/qgis/qwc2-demo-app/blob/master/js/SearchProviders.js) and [static/assets/searchProviders.js](https://github.com/qgis/qwc2-demo-app/blob/master/static/assets/searchProviders.js) for full examples.
125+
126+
Consult [static/assets/searchProviders.js](https://github.com/qgis/qwc2-demo-app/blob/master/static/assets/searchProviders.js) for a full examples.
103127

104128
## Filtering <a name="filtering"></a>
105129

@@ -138,18 +162,17 @@ searchProviders: [
138162
"<providerkey1>", // Simple form
139163
{ // Provider with custom params
140164
"provider": "<providerkey2>",
165+
"key": "<key>", // Optional: key to disambiguate multiple provider configurations of the same provider type (i.e. multiple `qgis` provider configurations)
166+
"label": "<label>", // Optional: provider label (displayed in provider selection menu). If not specified, the label/labelmsgid from the provider definition is used.
167+
"labelmsgid": "<msgid>", // Optional: translateable label message ID, instead of `label`
141168
"params": {
142-
... // Arbitrary params passed to the provider `onSearch` function as `searchParams.cfgParams`
169+
... // Additional params passed to the provider `onSearch` function as `searchParams.cfgParams`
143170
}
144-
},
145-
{ // Fulltext search configuration using qwc-fulltext-search-service
146-
"provider":"solr", // Identifier for solr search provider
147-
"default":[<default terms>] // Default search terms, concatenated with additional search terms from visible theme layers
148171
}
149-
],
172+
]
150173
...
151174
```
152-
Note: The `qwc2-demo-app` (also used by the `qwc-map-viewer-demo` docker image) includes three providers by default: `coordinates`, `nominatim` (OpenStreetMap location search), and `qgis` (see <a href="#qgis-search">below</a>).
175+
Note: The `qwc2-demo-app` (also used by the `qwc-map-viewer-demo` docker image) includes four providers by default: `coordinates`, `nominatim` (OpenStreetMap location search), `qgis` (see <a href="#qgis-search">below</a>) and `fulltext` (see <a href="#fulltext-search">below</a>).
153176

154177
## Configuring the QGIS feature search <a name="qgis-search"></a>
155178

@@ -407,9 +430,11 @@ To use a fulltext search in a theme, configure a `fulltext` search provider in `
407430
"searchProviders": [
408431
{
409432
"provider": "fulltext",
410-
"default": [<FACET_NAME>],
411-
"layers": {
412-
"<layer_name>": "<FACET_NAME>"
433+
"params": {
434+
"default": [<FACET_NAME>],
435+
"layers": {
436+
"<layer_name>": "<FACET_NAME>"
437+
}
413438
}
414439
}
415440
]

0 commit comments

Comments
 (0)