Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to group search results by category or layer title #1672

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Several global settings for the client can be configured via the [`gis-client-co
| search.coreName | Solr core name. | 'search' |
| search.defaultUseViewBox | Whether the search is restricted to the current view box. | true |
| search.useNominatim | Whether to use Nominatim. | true |
| search.groupByCategory | Groups search results by 'category' text field. If disabled, the layer title will be used instead. | true |
| search.useSolrHighlighting | Enable / disable solr search result highlighting. | true |
| search.delay | Delay in milliseconds before search is triggered (debouncing). | 1000 |
| search.minChars | Minimum search term length for the search to be triggered. | 3 |
Expand Down
1 change: 1 addition & 0 deletions resources/config/gis-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var clientConfig = {
coreName: 'search',
defaultUseViewBox: true,
useNominatim: true,
groupByCategory: true,
useSolrHighlighting: true,
delay: 1000,
minChars: 3,
Expand Down
27 changes: 24 additions & 3 deletions src/components/MultiSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import ClientConfiguration from 'clientConfig';
import _groupBy from 'lodash/groupBy';
import _isNil from 'lodash/isNil';

import { getUid } from 'ol';
import {
Extent as OlExtent
} from 'ol/extent';
Expand All @@ -50,6 +49,10 @@ import useMap from '@terrestris/react-geo/dist/Hook/useMap';
import SearchResultsPanel, {
Category as ResultCategory
} from '@terrestris/react-geo/dist/Panel/SearchResultsPanel/SearchResultsPanel';
import {
WmsLayer,
isWmsLayer
} from '@terrestris/react-geo/dist/Util/typeUtils';

import {
SearchConfig
Expand Down Expand Up @@ -382,8 +385,26 @@ export const MultiSearch: React.FC<MultiSearchProps> = ({
if (dataSearchResults?.length > 0) {

const wktFormat = new OlFormatWKT();
// 1. group by category
const categories = _groupBy(dataSearchResults, res => res?.category[0]);

// 1. group by category or layer title
let categories;
if (ClientConfiguration.search?.groupByCategory) {
categories = _groupBy(dataSearchResults, res => res?.category[0]);
} else {
const layers = map.getAllLayers().filter(l => l.get('searchable'));
const resultsWithLayerName = dataSearchResults.map(result => {
const layerTitle = layers.filter(l => isWmsLayer(l))
.find((l) => (l as WmsLayer).getSource()?.getParams()?.LAYERS === result.featureType[0])
?.get('name');

return {
layerTitle,
...result
} as DataSearchResult;
});
categories = _groupBy(resultsWithLayerName, res => res?.layerTitle);
}

// 2. build features
Object.keys(categories).forEach(category => {
const features = categories[category].map(dsResult => {
Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare module 'clientConfig' {
type SearchConfiguration = {
solrBasePath?: string;
useNominatim?: boolean;
groupByCategory?: boolean;
useSolrHighlighting?: boolean;
defaultUseViewBox?: boolean;
delay?: number;
Expand Down