Select to view content in your preferred language

Problem in esri search with suggestion template

1584
7
05-10-2019 05:34 AM
SurajShrestha
Emerging Contributor

I have used suggestion template in esri search widget. If I select data from suggestion list, then the search works well. But, if I manually enter same value in search input, and do search using search icon, then it does not give me any result.

You should be able to regenerate this problem in esri sample for search widget:

https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=search_suggestiontemplate

In this sample, if you search for '1930476016: 4519 Cherokee Ln', and select it from suggestion list, then search works. But, if you paste same value directly in search textbox, and do manual search using search button, then it does not show any result.

Could you please suggest me if I misunderstood search widget feature, and show me how to fix it? I am using esri 3.28 js version in my project.

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Suraj,

   Because in that sample the searchFields is not defined for that source the only field being searched is the ownername1 (i.e. the displayfield). If you add the required searchFields property to the source then you can search on any of those fields. If you make this change to the sample then you can search by OWNERNAME1 or PARCELID or SITEADDRESS. But searching for the exact suggestion template will Not work.

      var search = new Search({
        sources: [{
          featureLayer: new FeatureLayer("https://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/FeatureServer/0", {
            outFields: ["*"],
            infoTemplate: new InfoTemplate("Parcels", "Owner name: ${OWNERNME1}</br>Parcel ID: ${PARCELID}</br>Site address: ${SITEADDRESS}")
          }),
          outFields: ["OWNERNME1","PARCELID","SITEADDRESS"],
          searchFields:["OWNERNME1","PARCELID","SITEADDRESS"],
          displayField: "OWNERNME1",
          suggestionTemplate: "${PARCELID}: ${SITEADDRESS}",
          name: "Parcels",
          placeholder: "example: Shawn Smith",
          enableSuggestions: true
      }],
        map: map
      }, "search");
0 Kudos
SurajShrestha
Emerging Contributor

Thanks for pointing out problem in sample. But, I have both searchFields and suggestionTemplate configured in source, as in your suggestion. The search works from suggestions list, but not if I type text, and perform search.

I compared search queries fired when selecting from suggestions list, and manual search, and found former one picks different attribute for search, while manual search uses just entered text.

Is there anything to be configured in mapservice to use some attribute as default during search? Thanks for help.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Suraj,

The search works from suggestions list, but not if I type text, and perform search.

I am Not seeing the same thing once I define the searchFields. I can type an owner name and click enter on the key board and the search works.

0 Kudos
SurajShrestha
Emerging Contributor

I also find it working with searchFields defined. But, I am having issue with my mapservice using similar approach.

Is there any settings in mapservice to configure attribute as searchable?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

As long as your service has the suggest ability enabled then no there is no other setting needed.

0 Kudos
BrianFausel
Frequent Contributor

Hi Suraj,

It sounds like you might be having a similar problem to one we found in the Search and also the Near Me widget Search. Though we are just using the out-of-the-box Web AppBuilder hosted on ArcGIS Online. I haven't submitted a case with Support yet but will in the future.

In our situation using your example, we found a "bug" (or perhaps a misunderstanding of the configuration) where the user can type the first part of the string and then click the suggestion candidate on the Search result list. In this case the search works properly (user types "1930476016:" from your example and then clicks "1930476016: 4519 Cherokee Ln" from the candidate list). Map would zoom and highlight the proper area.

But as soon as the user types the space or anything further in the string, sometimes the Search fails and other times the Search returns some random neighboring feature (user types "1930476016: 4519 " and then clicks "1930476016: 4519 Cherokee Ln" from the candidate list). I'd be curious to see if you encounter a similar problem in your app?

0 Kudos
SurajShrestha
Emerging Contributor

Hi Brian,

Thanks for response. But, my problem is bit different than yours. I am doubtful if we can search with reference to any attribute present in mapservice. May be something needs to be configured in mapservice itself to perform search with specific attribute params.

Thanks for sharing.

0 Kudos