This sample demonstrates how to use the Search component to search multiple Layer Sources based on given fields.
The search component provides the capability to search features in Layers or geocode locations with a locator. By default, the Search component will focus the map on the SearchResult.
The level of detail (LOD) at the center of the map depends on the data source, with higher quality data sources returning extents closer to the feature obtained from the search.
To use multiple sources with the Search component, you must set the component’s sources property.
The geocoding service requires a token for authentication. This sample uses an API Key to authenticate. You can either replace it with your own API Key, or remove it and log in once prompted. Alternatively, you can use another authentication method to access the geocoding service.
At version 5.2, we introduced the searchMode property, which allows users to work better with Full-text indexed layers
than the deprecated exactMatch property.
See the Full-text indexes ArcGIS Pro documentation
and the Add indexes to attribute fields
ArcGIS Online documentation for more information. If the layer is not full-text indexed, the "full-text-simple" will fall back to "simple", and the "full-text-starts-with" will fall back to "starts-with".
Here is how we set-up the Search component in the sample:
const search = document.querySelector("arcgis-search"); await search.componentOnReady(); // set the search sources once the component is ready search.sources = [ { layer: featureLayerDistricts, searchFields: ["DISTRICTID"], displayField: "DISTRICTID", searchMode: "full-text-starts-with", outFields: ["DISTRICTID", "NAME", "PARTY"], name: "Congressional Districts", placeholder: "example: 3708", }, { layer: featureLayerSenators, searchFields: ["Name", "Party"], suggestionTemplate: "{Name}, Party: {Party}", searchMode: "full-text-starts-with", outFields: ["*"], placeholder: "example: Casey", name: "Senators", zoomScale: 500000, resultSymbol: { type: "picture-marker", // autocasts as new PictureMarkerSymbol() url: "%prefix%/assets/sample-code/%slug%/images/senate.avif", height: 36, width: 36, }, }, { name: "ArcGIS World Geocoding Service", placeholder: "example: Nuuk, GRL", singleLineFieldName: "SingleLine", apiKey: "YOUR_ACCESS_TOKEN", url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", }, ];