QUERYTASK and case sensitivity

3817
6
07-28-2011 05:44 PM
StephenLead
Regular Contributor III
What are the techniques recommended for handling case sensitivity in a query in the JS API?

The Query No Map sample is a perfect example - search on "CALIFORNIA" and it returns no results.

Is there a way to handle the situation where the user doesn't know the correct capitalisation required?

function execute(stateName) {
        query.text = stateName;
        queryTask.execute(query,showResults);
      }


You could convert query.text to upper- or lower-case, but that doesn't help unless the actual value in the geodatabase matches. Is there a flag to ignore the case in a query?

Thanks,
Steve
0 Kudos
6 Replies
HemingZhu
Occasional Contributor III
What are the techniques recommended for handling case sensitivity in a query in the JS API?

The Query No Map sample is a perfect example - search on "CALIFORNIA" and it returns no results.

Is there a way to handle the situation where the user doesn't know the correct capitalisation required?

function execute(stateName) {
        query.text = stateName;
        queryTask.execute(query,showResults);
      }


You could convert query.text to upper- or lower-case, but that doesn't help unless the actual value in the geodatabase matches. Is there a flag to ignore the case in a query?

Thanks,
Steve


query.text, as API stated, is "Shorthand for a where clause using "like". The field used is the display field defined in the map document. You can determine what the display field is for a layer in Services Directory".  Use query.where instead so that you could convert both end to upper case:
function execute(stateName) {
        query.where ="Upper(STATE_NAME) like '%" + stateName.toUpperCase() +"'%";
        queryTask.execute(query,showResults);
      }
     
0 Kudos
StephenLead
Regular Contributor III

query.where ="Upper(STATE_NAME) like '%" + stateName.toUpperCase() +"'%";


That works - thanks again.
0 Kudos
StephenLead
Regular Contributor III
query.where ="Upper(STATE_NAME) like '%" + stateName.toUpperCase() +"'%";


Just to add to this - using Upper() in the query seems to slow it down dramatically.

I found it much faster to convert the values to uppercase in the geodatabase (in an edit session within ArcMap), and simply use:

query.where ="STATE_NAME like '%" + stateName.toUpperCase() +"'%";


Steve
0 Kudos
HemingZhu
Occasional Contributor III
Just to add to this - using Upper() in the query seems to slow it down dramatically.

I found it much faster to convert the values to uppercase in the geodatabase (in an edit session within ArcMap), and simply use:

query.where ="STATE_NAME like '%" + stateName.toUpperCase() +"'%";


Steve


Of cause. Basically you eleminate an extra SQL function UPPER().
0 Kudos
KennethRichards
New Contributor III
How would you write this if you wanted to query using a second attribute as well?
0 Kudos
StephenLead
Regular Contributor III
How would you write this if you wanted to query using a second attribute as well?


You could use something like:


query.where ="STATE_NAME like '%" + stateName.toUpperCase() +"'% AND SECOND_ATTRIBUTE like %" + secondValue.toUpperCase() + "%"


(I haven't verified that it all balances out, but the key thing is to use an AND statement in the URL query).
0 Kudos