search-ui

This bundle offers a user interface for searching in multiple data sources. If a search result is selected, the actions that are configured in this bundle are performed.

Search results are provided by the SearchService service implementation of the search-api bundle.

The API of this bundle is described in detail in the API documentation.

Usage

No configuration is required. Default values are applied.

The widget is registered at the component system with the widget role search-ui.

Configuration reference

The following code sample shows all configurable properties and their default values:

"search-ui": {
    "Config": {
        "actions": [
            "zoomto",
            "highlight",
            "openpopup"
        ],
        "maxResultsPerGroup": 5,
        "showTotalResultsCount": false,
        "placeholderText": "${search.placeholder}",
        "searchDelay": 100,
        "zoomto-point-scale": 1000,
        "<action-property>": "value"
    }
}
Property Type Description
actions Array A list of actions to execute when a search result is selected. For a list of available actions, see the map-actions bundle.
maxResultsPerGroup Number The maximum number of results shown per result group.
showTotalResultsCount Boolean To show the total number of results per result group, set this property to true.
placeholderText String Placeholder text for the search input field. Default is "Search for ..." message (with translation support).
searchDelay Number The delay in milliseconds to wait until a new search is executed. Default is 100 milliseconds.
zoomto-point-scale Number Scale to zoom to if geometry is of type point.

Configure actions

For more information about configuration options of the default actions, see the map-actions bundle documentation.

Use cases

How to configure actions

For configuration options of the highlight and zoomto actions consider the map-actions documentation. To use the openpopup action define a popupTemplate. See map-actions how to add custom actions, too.

How to add custom actions

For more information about adding custom actions, see the map-actions bundle.

How to define the order of search results

This bundle shows search results in an order that matches the search priority of the given data sources:

The following code sample shows an app configuration with different stores:

"agssearch": {
    "AGSStore":[
        {
            "id": "Countries",
            "url": "https://myserver/arcgis/rest/services/Countries/MapServer/0",
            "searchPriority": 1
        },
        {
            "id": "Cities",
            "url": "https://myserver/arcgis/rest/services/Cities/MapServer/0",
            "searchPriority": 2
        },
        {
            "id": "Addresses",
            "url": "https://myserver/arcgis/rest/services/Addresses/MapServer/0",
            "searchPriority": 3
        },
        {
            "id": "Streets",
            "url": "https://myserver/arcgis/rest/services/Streets/MapServer/0",
            "searchPriority": 3
        }
    ]
}

The search results are displayed in the following order:

  1. Countries
  2. Cities (after the search for Countries has finished)
  3. Addresses or Streets (after the search for Cities has also finished) depending on which store is faster.

If searchPriority is not explicitly defined for a store, the priority value 50 is applied.

Reset the search-ui programmatically

To reset the current search programmatically, for example because a new workflow is started, perform the following steps:

First inject the search-ui.SearchUiService to your bundle:

"components": [
    {
        "name": "MyComponent",
        "references": [{
            "name": "searchUiService",
            "providing": "search-ui.SearchUiService"
        }]
    }
]

To reset the search, use the reset() method as follows:

import { InjectedReference } from "apprt-core/InjectedReference";
import { SearchUiService } from "search-ui/api";

private searchUiService: InjectedReference<SearchUiService>;
...
searchUiService!.reset();

Set a text in the search-ui programmatically

The previously described reset() method also accepts a searchText value, which sets a text in the input field, but will not trigger a search:

searchUiService.reset({ searchText: "My search term" });

Define a custom action for <ENTER> key press

To define a custom behaviour when pressing the <ENTER> key while typing a search term, you can use the SearchUiEnterKeyAction interface.

The code inside it's trigger() method is executed, when you press the <ENTER> key while the focus is inside the search-ui's text-input. Furthermore, you can be notified, when the search-ui's input is cleared. To do so, you can implement some code inside the reset() method. This is optional.

To implement a custom action, first inject the search-ui.SearchUiService to your bundle:

"components": [{
    "name": "CustomEnterKeyAction",
    "provides": ["search-ui.EnterKeyAction"],
}]

NOTE: Only a single EnterKeyAction is allowed to be registered at the same time.

Then implement the logic for your custom action like in the following example:

import { InjectedReference } from "apprt-core/InjectedReference";
import { SearchUiEnterKeyAction } from "search-ui/api";

export class CustomEnterKeyAction implements SearchUiEnterKeyAction {
    description = "An optional description for the action. It will appear as tooltip for the magnifying glass icon button of the search-ui and as its aria-label.";
    trigger(inputText: string): void {
        console.info(`Action 'trigger' triggered with '${inputText}'`);
    }
    reset(): void {
        console.info("Action 'reset' was triggered");
    }
}