<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to filter Search Widget Results to certain categories in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208482#M78535</link>
    <description>&lt;P&gt;I've got a very customized &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html" target="_self"&gt;Search Widget&lt;/A&gt; in an ArcGIS JavaScript API app. I would like to have it configured so that "keyword" search results are not suggested in autosuggest. For example, if I type "Piz", I don't want to see "Pizza" as an option.&lt;/P&gt;&lt;P&gt;I'm okay with most other categories of results, although I might wish to filter results further.&lt;/P&gt;&lt;P&gt;I've currently got my searchWidget configured like so:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const searchWidget = new Search({
        includeDefaultSources: false,
        maxSuggestions: 5,
        minSuggestCharacters: 2,
        popupEnabled: false,
        sources: [
          {
            apiKey: ourAPIKey,
            filter: { geometry: bufferExtent},
            locator: new LocatorSearchSource({
              categories: ["Point Address"], //or whatever I want
              url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", // default
            }),
            name: "ArcGIS World Geocoding Service",
          },
          ...layerSources.filter((l) =&amp;gt; l !== null), // other custom layer sources
        ],
        view: this.props.view,
      });
//... some stuff
const suggestions = await searchWidget.suggest("piz");&lt;/LI-CODE&gt;&lt;P&gt;But this seems to have no effect. I've had this problem at 4.20, tried at 4.23 no difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was assuming that supplying a string list of &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSource.html#categories" target="_self"&gt;categories&lt;/A&gt;&amp;nbsp;from &lt;A href="https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm#ESRI_SECTION1_502B3FE2028145D7B189C25B1A00E17B" target="_self"&gt;here&lt;/A&gt; to the LocatorSearchSource would do the trick but it seems not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone know what needs to be done?&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SearchProblem.gif" style="width: 508px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50074i7325F76E3B1C32CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="SearchProblem.gif" alt="SearchProblem.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2022 22:15:42 GMT</pubDate>
    <dc:creator>RyanSutcliffe</dc:creator>
    <dc:date>2022-08-31T22:15:42Z</dc:date>
    <item>
      <title>How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208482#M78535</link>
      <description>&lt;P&gt;I've got a very customized &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html" target="_self"&gt;Search Widget&lt;/A&gt; in an ArcGIS JavaScript API app. I would like to have it configured so that "keyword" search results are not suggested in autosuggest. For example, if I type "Piz", I don't want to see "Pizza" as an option.&lt;/P&gt;&lt;P&gt;I'm okay with most other categories of results, although I might wish to filter results further.&lt;/P&gt;&lt;P&gt;I've currently got my searchWidget configured like so:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const searchWidget = new Search({
        includeDefaultSources: false,
        maxSuggestions: 5,
        minSuggestCharacters: 2,
        popupEnabled: false,
        sources: [
          {
            apiKey: ourAPIKey,
            filter: { geometry: bufferExtent},
            locator: new LocatorSearchSource({
              categories: ["Point Address"], //or whatever I want
              url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer", // default
            }),
            name: "ArcGIS World Geocoding Service",
          },
          ...layerSources.filter((l) =&amp;gt; l !== null), // other custom layer sources
        ],
        view: this.props.view,
      });
//... some stuff
const suggestions = await searchWidget.suggest("piz");&lt;/LI-CODE&gt;&lt;P&gt;But this seems to have no effect. I've had this problem at 4.20, tried at 4.23 no difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was assuming that supplying a string list of &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-LocatorSearchSource.html#categories" target="_self"&gt;categories&lt;/A&gt;&amp;nbsp;from &lt;A href="https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm#ESRI_SECTION1_502B3FE2028145D7B189C25B1A00E17B" target="_self"&gt;here&lt;/A&gt; to the LocatorSearchSource would do the trick but it seems not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone know what needs to be done?&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SearchProblem.gif" style="width: 508px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50074i7325F76E3B1C32CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="SearchProblem.gif" alt="SearchProblem.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 22:15:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208482#M78535</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2022-08-31T22:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208500#M78538</link>
      <description>&lt;P&gt;In older versions of ESRI ArcGIS JavaScript API, I have had success with making a fetch request to &lt;A href="https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm" target="_self"&gt;findAddressCandidates&lt;/A&gt; for each suggestion result using the `key` as the `magickey`. With the response for each suggestion, if the response had more than one candidate there, I would ignore it. That worked until now, where I am seeing some CORS issues with my tool refactored for API version 4.23+.&amp;nbsp;&lt;BR /&gt;But in any case, it wasn't a great process, because I'd have to make a large amount of requests to the geocoding service. So I'm hoping there is a better way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 16:27:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208500#M78538</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2022-09-01T16:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208698#M78552</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6031"&gt;@RyanSutcliffe&lt;/a&gt;,&amp;nbsp;have you tried with "Address" instead of "Point Address"? I'm wondering if you need to use a Category Level 1 property instead of a Category Level 2: category:&amp;nbsp;&lt;A href="https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm" target="_blank"&gt;https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Also, note that Locator is no longer supported for the Search widget sources, you can use the `url` property instead:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/breaking-changes/#424" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/breaking-changes/#424&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 14:38:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208698#M78552</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2022-09-01T14:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208761#M78561</link>
      <description>&lt;P&gt;I took a second look through the API docs this morning. I was mistaking the structure of the object being passed to the Search instance. The correct usage is as per below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; const searchWidget = new Search({
        includeDefaultSources: false,
        maxSuggestions: 5,
        minSuggestCharacters: 2,
        popupEnabled: false,
        sources: [
          new LocatorSearchSource({
            apiKey: mytoken,
            categories: [
              "Address",
              "Postal",
              "Populated Place",
              "Land Features",
              "Water Features",
            ],
            filter: { geometry: bufferExtent },
            name: "ArcGIS World Geocoding Service",
            url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/",
          }),

          ...layerSources.filter((l) =&amp;gt; l !== null),
        ],
        view: this.props.view,
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the LocatorSearchSource is up a level and itself includes the url and other properties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works in filtering values to certain categories. It seems, by excluding "POI" values I don't get keyword search results like: "Pizza", "Italian", "Groceries" etc. Its not perfect, for example I would like to still have things like business name searches return specific addresses. So I want specific POI related addresses, just not keyword results.&lt;/P&gt;&lt;P&gt;If anyone knows a trick where the search term "Pizza" will return specific Pizza-named business addresses but not a keyword with many results I'll mark that as the answer.&lt;/P&gt;&lt;P&gt;As &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt; pointed out, 'locator' should now be 'url' and is needed at 4.24+. I've updated that in this revised working sample.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 16:35:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208761#M78561</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2022-09-01T16:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208794#M78562</link>
      <description>&lt;P&gt;If there's no means of telling the server not to return keyword results, then the alternative would be to strip them out from the response before that response is received by the Search widget.&amp;nbsp; Have you considered using a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#RequestInterceptor" target="_self"&gt;RequestInterceptor&lt;/A&gt;?&amp;nbsp; These can be added via the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html" target="_self"&gt;esriConfig&lt;/A&gt;.&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#request" target="_self"&gt;request&lt;/A&gt; property.&amp;nbsp; Using this, you can examine the suggestions in the response, and strip out any that have &lt;A href="https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm" target="_self"&gt;isCollection&lt;/A&gt; set to true before the widget receives those results.&amp;nbsp; Since some results are therefore likely to be stripped out, you might also consider increasing your maxSuggestions setting.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 17:36:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1208794#M78562</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2022-09-01T17:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1209955#M78601</link>
      <description>&lt;P&gt;That's a good point&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/6522"&gt;@JoelBennett&lt;/a&gt;.&amp;nbsp;&lt;BR /&gt;I just looked into it now-- it turns out that when you use the `.suggest` method on a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html" target="_self"&gt;Search class&lt;/A&gt; instance, the result data structure you get back is &lt;EM&gt;different than if you made a raw fetch&lt;/EM&gt; to the API url. So `.suggest` returns an object with a results property that is a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SuggestResult" target="_self"&gt;SuggestResponse object.&lt;/A&gt;&amp;nbsp;You can see that in there, there is no &lt;EM&gt;isCollection&lt;/EM&gt; property returned!&lt;BR /&gt;If I look at what actual request is sent over the network I can see that it is still a suggest request under the hood. eg:&lt;BR /&gt;&amp;gt;&amp;nbsp;&lt;A href="https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest" target="_blank"&gt;https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest&lt;/A&gt;&lt;BR /&gt;Which has the `isCollection` property that I need. It just doesn't get exposed in the API.&lt;BR /&gt;&lt;BR /&gt;That's too bad because that would be a lot easier. I guess that is why you are proposing using the &lt;STRONG&gt;RequestInteceptor&lt;/STRONG&gt; approach, where you can modify any esriRequest right at the network level. I guess I could add logic there, although I am a bit wary of inserting logic that fires after every esri-based network request.&lt;BR /&gt;Not sure if I'll give this a whirl myself or just drop support for POI results completely for my own use case.&lt;/P&gt;&lt;P&gt;The other solution that this brings up for me (or others who really just want the business logic) is that I might consider dropping the Search class entirely. I've got a completely customized UX and a component with its own methods and could probably just wire in raw esriRequest calls which would get me the data structure with isCollection that I need. Not sure, but might not really need the full class for my use case.&lt;BR /&gt;&lt;BR /&gt;I'm going to accept this as the best solution unless someone pipes in with a better approach.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 16:23:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1209955#M78601</guid>
      <dc:creator>RyanSutcliffe</dc:creator>
      <dc:date>2022-09-06T16:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter Search Widget Results to certain categories</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1209990#M78602</link>
      <description>&lt;P&gt;After looking into this a little further, I've found the Search widget calls the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-locator.html" target="_self"&gt;locator&lt;/A&gt;.&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-locator.html#suggestLocations" target="_self"&gt;&lt;SPAN&gt;suggestLocations&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;method, which returns an array of &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-locator.html#SuggestionResult" target="_self"&gt;SuggestionResult&lt;/A&gt; objects that differ slightly than the SuggestResult objects you mentioned above.&amp;nbsp; These SuggestionResult objects do contain the isCollection property, but that information gets lost in esri/widgets/Search/support/locatorUtils when they get transformed into SuggestResult objects.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt;&amp;nbsp;any chance that isCollection values can get carried over into&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#SuggestResult" target="_self"&gt;SuggestResult&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 17:31:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-filter-search-widget-results-to-certain/m-p/1209990#M78602</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2022-09-06T17:31:46Z</dc:date>
    </item>
  </channel>
</rss>

