Skip to content

Commit df6b00e

Browse files
Merge pull request #487 from Dataport/implement-server-side-sorting-for-wfs-feature-requests
Implement server side sorting for wfs feature requests
2 parents e1dab1e + 4704f5a commit df6b00e

File tree

8 files changed

+52
-7
lines changed

8 files changed

+52
-7
lines changed

packages/clients/dish/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Feature: Monumental label layer toggles its visibility depending on visible monumental layer geometries.
66
- Feature: Alkis layer is switched to visible after parcel search result is picked.
7+
- Feature: Search results for 'Flurstückssuche' are sorted by the server.
78
- Fix: Add new configuration parameters for DishExportMap to configure different host (backend host might differ from `internalHost`) and to simplify adjustments for backend changes.
89
- Fix: Add terms of use for internal map.
910
- Fix: Open links for BKG and their terms of use in new tab.

packages/clients/dish/src/mapConfigurations/searchConfigParams.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ export const searchMethods = {
107107
'{{gemarkung}} {{flur}}, {{flstnrzae}}, {{flstkennz}}',
108108
'{{flstkennz}}',
109109
],
110+
sortBy: [
111+
{ propertyName: 'gemarkung', direction: 'ASC' },
112+
{ propertyName: 'flur', direction: 'ASC' },
113+
{ propertyName: 'flstnrzae', direction: 'ASC' },
114+
{ propertyName: 'flstnrnen', direction: 'ASC' },
115+
],
110116
},
111117
},
112118
}

packages/lib/getFeatures/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unpublished
4+
5+
- Feature: Implement server-side sorting for `getWfsFeatures`. Can be configured by new parameter `sortBy`.
6+
37
## 3.1.1
48

59
- Fix: On server returns with the CRS not indicated on the root element, but on its children, the projection is now inferred from those.

packages/lib/getFeatures/tests/wfs.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('tools/lib/getFeatures/wfs', () => {
110110
it('creates a one-query search for a single match', () => {
111111
const filterXmlString = buildWfsFilter([[['a', '5']]], parameters)
112112
expect(filterXmlString).toEqual(
113-
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query></wfs:GetFeature>'
113+
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com" xmlns:ogc="http://www.opengis.net/ogc"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query></wfs:GetFeature>'
114114
)
115115
})
116116

@@ -125,7 +125,7 @@ describe('tools/lib/getFeatures/wfs', () => {
125125
parameters
126126
)
127127
expect(filterXmlString).toEqual(
128-
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:And><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:b</ogc:PropertyName><ogc:Literal>3*</ogc:Literal></ogc:PropertyIsLike></ogc:And></ogc:Filter></wfs:Query></wfs:GetFeature>'
128+
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com" xmlns:ogc="http://www.opengis.net/ogc"><ogc:Filter><ogc:And><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:b</ogc:PropertyName><ogc:Literal>3*</ogc:Literal></ogc:PropertyIsLike></ogc:And></ogc:Filter></wfs:Query></wfs:GetFeature>'
129129
)
130130
})
131131

@@ -135,7 +135,7 @@ describe('tools/lib/getFeatures/wfs', () => {
135135
parameters
136136
)
137137
expect(filterXmlString).toEqual(
138-
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com"><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:b</ogc:PropertyName><ogc:Literal>3*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query></wfs:GetFeature>'
138+
'<?xml version="1.0" encoding="UTF-8"?><wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" maxFeatures="999"><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com" xmlns:ogc="http://www.opengis.net/ogc"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:a</ogc:PropertyName><ogc:Literal>5*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query><wfs:Query typeName="prefix:TyPeNaMe" xmlns:prefix="example.com" xmlns:ogc="http://www.opengis.net/ogc"><ogc:Filter><ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!"><ogc:PropertyName>prefix:b</ogc:PropertyName><ogc:Literal>3*</ogc:Literal></ogc:PropertyIsLike></ogc:Filter></wfs:Query></wfs:GetFeature>'
139139
)
140140
})
141141
})

packages/lib/getFeatures/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export interface WfsParameters extends QueryParameters {
6161
useRightHandWildcard?: boolean
6262
/** custom attributes for the like operators in filters */
6363
likeFilterAttributes?: Record<string, string>
64+
/** Sorting definition for WFS features; e.g. [\{ propertyName: 'name', direction: 'DESC' \}] */
65+
sortBy?: { propertyName: string; direction?: 'ASC' | 'DESC' }[]
6466
}
6567

6668
/**

packages/lib/getFeatures/wfs/buildWfsFilter.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ const queryPrefix = ({
2222
typeName,
2323
xmlns,
2424
}: WfsParameters) => `
25-
<wfs:Query typeName="${featurePrefix}:${typeName}" xmlns:${featurePrefix}="${xmlns}"${
25+
<wfs:Query typeName="${featurePrefix}:${typeName}" xmlns:${featurePrefix}="${xmlns}" xmlns:ogc="http://www.opengis.net/ogc"${
2626
srsName ? ` srsName="${srsName}"` : ''
2727
}>
28-
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">`
28+
<ogc:Filter>`
2929

3030
const wfsLike = (
3131
fieldName: string,
@@ -53,7 +53,29 @@ const wfsLike = (
5353
</ogc:PropertyIsLike>`
5454
}
5555

56-
const querySuffix = `</ogc:Filter></wfs:Query>`
56+
const querySortBy = (
57+
sortBy: { propertyName: string; direction?: 'ASC' | 'DESC' }[],
58+
featurePrefix: string
59+
) => `<ogc:SortBy>
60+
${sortBy
61+
.map(
62+
({ propertyName, direction = 'ASC' }) =>
63+
`<ogc:SortProperty>
64+
<ogc:PropertyName>${featurePrefix}:${propertyName}</ogc:PropertyName>
65+
<ogc:SortOrder>${direction}</ogc:SortOrder>
66+
</ogc:SortProperty>`
67+
)
68+
.join('')}
69+
</ogc:SortBy>`
70+
71+
const querySuffix = (
72+
sortBy?: { propertyName: string; direction?: 'ASC' | 'DESC' }[],
73+
featurePrefix?: string
74+
) =>
75+
`</ogc:Filter>${
76+
sortBy?.length && featurePrefix ? querySortBy(sortBy, featurePrefix) : ''
77+
}
78+
</wfs:Query>`
5779

5880
const getFeatureSuffix = `</wfs:GetFeature>`
5981

@@ -72,7 +94,7 @@ const buildWfsFilterQuery = (
7294
request += wfsLike(key, value, parameters)
7395
}
7496

75-
return request + querySuffix
97+
return request + querySuffix(parameters.sortBy, parameters.featurePrefix)
7698
}
7799

78100
/**

packages/plugins/AddressSearch/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unpublished
4+
5+
- Feature: Add new parameter `sortBy` to type `WfsParameter` for server-side sorting of WFS search results.
6+
37
## 3.2.0
48

59
- Feature: Add optional `resultModifier` option to `searchMethodsObject` that allows modifying a result before adding it to the store.

packages/plugins/AddressSearch/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ queryParameters: {
228228
| likeFilterAttributes | Record<string, string>? | As specified by the [OGC-Standard for filters](https://schemas.opengis.net/filter/) the `PropertyIsLike` operator requires three attributes (e.g. in WFS 2.0.0: `wildCard`, `singleChar` and `escapeChar`). These may vary in value and (with other WFS versions) also in property definition. Therefore, it is possible to configure the values of the attributes needed for WFS 2.0.0 and also to add custom attributes needed for other versions. Defaults to `{wildCard: "\*", singleChar: ".", escapeChar: "!"}`. |
229229
| patternKeys | Record<string, string>? | Maps field names from patterns to regexes. Each field name has to have a definition. Each regex must have one capture group that is used to search. Contents next to it are ignored for the search and just used for matching. E.g. `'([0-9]+)$'` would be a value for a key that fits an arbitrary number string at the input's end. |
230230
| patterns | string[]? | Allows specifying input patterns. In a single-field search, a pattern can be as easy as `{{theWholeThing}}`, where `theWholeThing` is also the feature field name to search in. In more complex scenarios, you may add separators and multiple fields, e.g. `{{gemarkung}} {{flur}} {{flstnrzae}}/{{flstnrnen}}` would fit many parcel search services. Mutually exclusive to `fieldName`. |
231+
| sortBy | Array<{propertyName: string; direction?: 'ASC' \| 'DESC'}>? | Server-side sorting criteria for WFS features. Features will be sorted by the properties in order of their appearance. The first property has highest priority. Direction defaults to 'ASC' if not specified. Applied after the filter, before results are returned. Please note that the server must support server-side sorting. |
231232
| srsName | string? | Name of the projection (srs) for the query. |
232233
| useRightHandWildcard? | boolean? | By default, if searching for "search", it is sent as "search*". This behaviour can be deactivated by setting this parameter to `false`. |
233234

@@ -248,6 +249,11 @@ queryParameters: {
248249
featurePrefix: 'app',
249250
xmlns: 'http://www.deegree.org/app',
250251
useRightHandWildcard: true,
252+
sortBy: [
253+
{ propertyName: 'street', direction: 'ASC' },
254+
{ propertyName: 'housenumber', direction: 'ASC' },
255+
{ propertyName: 'city', direction: 'ASC' },
256+
],
251257
}
252258
```
253259

0 commit comments

Comments
 (0)