Select to view content in your preferred language

FeatureLayer (Search with featureLayer)

1091
5
Jump to solution
03-06-2012 07:32 AM
FaizanTayyab
Deactivated User
Hello All,

i am trying to use the search with featureLayer sample. i have a feature layer and am using in a loop (as obj.name changes)
queryExpression = queryExpression + customLayer.layerDetails.fields[3].name + " like '%" + obj.name + "%'"+" OR " if(queryExpression.length > 4) {  queryExpression = queryExpression.substring(0,queryExpression.length - 4); } customLayer.definitionExpression = queryExpression


The above works fine and the featurelayer is filtered based upon the query if there are only 10 increments in the loop meaning there are around 9 'ORs' in the queryExpression statement. However the moment another OR is appended to the queryExpression, i get a unable to complete operation error.

Does this mean that within the definitionExpression, only 9 OR operators can be used? Is there such limit.

What i want to achieve is based upon the obj.name which can be from 1 to 100, i want to highlight the features which fullfill the query conditions.

Any help appreciated.

Is there anyway to filter features based not on only one value but multiple values.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Faizan,

   I do believe that you should still attempt to use the IN operator. Just loop through all your results creating a comma separated list and then when you are done looping add the list to the SQL expression using the IN operator. I believe that you will find that the resulting SQL Expression will function better. So did you figure out how to escape your single quote in the data?

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Faizan,

   Well it seems like your issue is a inexperience with SQL statements. The cost of doing a "LIKE" statement in a query is very expensive compared to a "=" and then you are tacking on multiple likes using OR and this turns out to be a Extremely poorly written SQL Statement that is VERY expensive. You need to get away from LIKE queries if at all possible and if you are going to use Multiple AND or ORs in your Query than you need to use "IN".

queryExpression = customLayer.layerDetails.fields[3].name + " IN (1,2,3,4,5,6,7,8,9,10)";


Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
0 Kudos
FaizanTayyab
Deactivated User
Thanks for the reply. I am aware of use of IN however in my case, because the queryexpression is built dynamically through looping, i think IN cannot be used. If i am not wrong IN can be used if the possible values and number of values are known, however in my case the obj.name is retrieved through another query.

I did find the reason for the query not working, it was due to ' in the query expression because some of the obj.name value have ' in them hence the query expression gets corrupted.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Faizan,

   I do believe that you should still attempt to use the IN operator. Just loop through all your results creating a comma separated list and then when you are done looping add the list to the SQL expression using the IN operator. I believe that you will find that the resulting SQL Expression will function better. So did you figure out how to escape your single quote in the data?
0 Kudos
FaizanTayyab
Deactivated User
Faizan,

   I do believe that you should still attempt to use the IN operator. Just loop through all your results creating a comma separated list and then when you are done looping add the list to the SQL expression using the IN operator. I believe that you will find that the resulting SQL Expression will function better. So did you figure out how to escape your single quote in the data?


Will give that a go. Thanks. For the single quote, i am cleaning the data in the mxd.

Regards
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Faizan,

    Cleaning the data will work, but you did not have to go to that extreme. You could have escaped the single quotes in your data by using a replace and replacing a single quote with two single quotes.

value = value.replace("'","''");
0 Kudos