You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
7
69
Update to qwc2 submodule revision [9cb8bab](https://github.com/qgis/qwc2/tree/9cb8bab) (13.11.2024)
Copy file name to clipboardExpand all lines: src/topics/Interfacing.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ The following parameters can appear in the URL of the QWC2 application:
15
15
-`crs`: The CRS of extent/center coordinates
16
16
-`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.
17
17
-`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.
19
19
-`f`: A filter configuration, see [Map filtering](./MapFilter.md).
20
20
-`localConfig`: Override the name of the loaded config file, i.e. to load `myconfig.json` instead of the default `config.json`, pass `localConfig=myconfig`.
21
21
@@ -44,8 +44,8 @@ The `urlPositionCrs` parameter in `config.json` determines the projection to use
44
44
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.
45
45
46
46
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>`
49
49
50
50
See [Fulltext search](Search.md#fulltext-search) for more details.
Copy file name to clipboardExpand all lines: src/topics/Search.md
+70-45Lines changed: 70 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -6,33 +6,40 @@ QWC2 can be configured to use arbitrary custom search providers. In addition, th
6
6
7
7
Search providers can be defined as follows:
8
8
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:
10
10
```js
11
-
exportconstSearchProviders= {
11
+
window.QWC2SearchProviders= {
12
12
<providerkey1>:<ProviderDefinition1>,
13
13
<providerkey2>:<ProviderDefinition2>,
14
14
...
15
15
};
16
16
```
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
This file needs to be imported into the application, i.e. via
31
+
```js
32
+
import'./SearchProviders.js';
30
33
```
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
+
31
38
The format of `ProviderDefinition` is
32
39
```js
33
40
{
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`
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
// layer definition, in the same format as a "sublayers" entry in themes.json
64
+
constlayer= {<layer_definition>};
65
+
callback(layer);
66
+
}
67
+
}
53
68
}
54
69
```
55
70
*Notes:*
@@ -60,9 +75,11 @@ The format of `ProviderDefinition` is
60
75
displaycrs:"EPSG:XXXX", // Currently selected mouse coordinate display CRS
61
76
mapcrs:"EPSG:XXXX", // The current map CRS
62
77
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
66
83
}
67
84
```
68
85
*`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
71
88
```js
72
89
results = [
73
90
{
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
77
97
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
88
111
},
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..}
94
120
}
95
121
]
96
-
},
97
-
{
98
-
...
99
122
}
100
123
]
101
124
```
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.
103
127
104
128
## Filtering <aname="filtering"></a>
105
129
@@ -138,18 +162,17 @@ searchProviders: [
138
162
"<providerkey1>", // Simple form
139
163
{ // Provider with custom params
140
164
"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.
... // Arbitrary params passed to the provider `onSearch` function as `searchParams.cfgParams`
169
+
... // Additional params passed to the provider `onSearch` function as `searchParams.cfgParams`
143
170
}
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
148
171
}
149
-
],
172
+
]
150
173
...
151
174
```
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 <ahref="#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 <ahref="#qgis-search">below</a>) and `fulltext` (see <ahref="#fulltext-search">below</a>).
153
176
154
177
## Configuring the QGIS feature search <aname="qgis-search"></a>
155
178
@@ -407,9 +430,11 @@ To use a fulltext search in a theme, configure a `fulltext` search provider in `
0 commit comments