Search Widget Dropdown Suggestions - Only Ones That "Start With" The Search Term

2208
3
01-26-2021 08:31 PM
DaveFullerton
Occasional Contributor III

I am using a feature layer search source with the Search Widget.  The feature layer contains address points that have addresses with apartment numbers.  There are some single digit address numbers, such as 8 Wyclow St.  When users enter 8 into the input box, the top 6 suggestions do not include 8 Wyclow St or even, for example, 8000 Main St.  Instead the top suggestions presented are addresses with the character '8' elsewhere in the address text.

Here the suggestions for '8':

image.png

Here are the suggestions for '8 ':

image.png

And for '8 W':

image.png

Is there a way to set the Search Widget or Layer Search Source to limit the search using the like operator so that the query would be <searchField> like '<searchTerm>%'?

My LayerSearchSource Properties:

searchFields: ["MailAddLine"],
displayField: "MailAddLine",
exactMatch: true,
outFields: ["*"],
name: "JOCO Address Points",
placeholder: "Enter Address",
maxResults: 6,
maxSuggestions: 6,
suggestionsEnabled: true,
minSuggestCharacters: 0,
zoomScale: 1000,
orderByFields: ["MailAddLine"]

3 Replies
Noah-Sager
Esri Regular Contributor
DaveFullerton
Occasional Contributor III

Thanks for the suggestion, Noah.  Could you be more specific?  I tried out a lot of things using prefix and suffix, but that didn't get me anywhere. 

Without setting prefix or suffix in the layerSearchSource:
I looked at the REST URL query through Chrome's Network tab.  It looks as though it is already using the LIKE operator and putting on '%' as a prefix and suffix:
 
...&where=(UPPER(MailAddLine)%20LIKE%20%27%25SEARCH TERM%25%27)...
 
i.e., ...&where=(UPPER(MailAddLine) LIKE '%SEARCH TERM%')...
 
I would just like to remove the first %:
i.e., ...&where=(UPPER(MailAddLine) LIKE 'SEARCH TERM%')...
 
 
 

 

Alexandr
New Contributor

Hi @Noah-Sager,

I tried use LayerSearchSource.prefix and suffix, but it seems those properties aren't suitable to "Starts with"-like search, because search term for "where" expression in that case just concatenated with prefix/suffix AND "%" symbol on BOTH sides.

Here is my try based on "Search widget with multiple sources" (ArcGIS JS API v4.18):

https://codepen.io/alexader2021/pen/PobQRYJ?editors=1000

 - as you can see, I set prefix/suffix properties as "FOO"/"BAR" for first search source, and ONLY suffix "%" for the second one. Here are queries that I see in network:

Alexandr_1-1614358768845.png

Alexandr_2-1614358901836.png

Another words, search term is always surrounded with "%" symbol irrespectively to prefix/suffix.

Is there any way to implement "Starts with" search behavior, so that search term ends with "%", but not starts with?

Thank you for advance!