Unordered suggestions and results in feature search (ArcGIS Online)

1138
3
06-12-2017 06:39 AM
WebGISGdibx
New Contributor III

I bulit an App in ArcGIS Online with Web AppBuilder an added the "Search Widget". For several layers in my WebMap I chose the search from feature layer.

Well, it works more or less good... If I know exactly how to type a place, it will be found. It also works that suggestions are displayed.

But what I absolutely not understand: if I type just one or some letters the order of the displayed suggestions and results is really weird. It's completely not alphabetical.

For example: I choose the layer "Playgrounds" to search and type "An" into the search field. I get suggestions of all Playgrounds with an "an" in some space, no matter if they are the first letters oder the last or somewhere in the middle of the word.

I will attach a screenshot of this example search:

It would be nicer if the suggestions/results were ordered logically, like:

- An der AOK

- An der Helmholtzschule

- etc.

Is there a solution or is it a bug... or even a feature and no one's bothered about it but me?

3 Replies
HemingZhu
Occasional Contributor III

I think ESRI should provide the property or function to do just that. But it is true that you can easily sort the search widget's suggestions so it will display in order on suggestion menu. Here is how i would do it: 

searchWidget.on("suggest-complete", function (e) {
   if (searchWidget.suggestions != null) {
      searchWidget.suggestions[0].results.sort(suggestionsCompare);
   }

});

function suggestionsCompare(a, b) {
      if (a.text < b.text)
         return -1;
      if (a.text > b.text)
         return 1;
      return 0; // equal

}

BrittanyMcKnight1
New Contributor III

Heming - I'm assuming you added this code to one of Web AppBuilder's (Dev) files for the search widget. Could you shed some light please on which file you added this code to? 

Thanks!

0 Kudos
BrittanyMcKnight1
New Contributor III

We are experiencing the same issue on our end. 

Setup a feature layer search within Web AppBuilder's search widget (AGOL and Web AppBuilder Dev 2.8). The water body's name has been set as the search and display fields. Maximum suggestions and results are set to 20 and the option to return an exact match is enabled. 

If I type in the letter 'p' into the search the results are ordered the way they are in the data layer, which is alphabetically, and the results also include anything containing a letter 'p.' So basically the query is LIKE '%p%' where I'm wanting LIKE 'p%'

I know the current results are going to be very confusing to our end users, which is the general public. 

Executing the preferred query through the hosted service's REST returns the expected results. 

As a side, the filter and query widgets in Web AppBuilder work the way I'd expect when searching for unique values by water body name. 

0 Kudos