gis.content.search() parameter substitution

6303
14
Jump to solution
08-09-2018 09:09 AM
RobertHolliday
New Contributor III

Greetings,

I am using the ArcGIS API for Python and I am struggling with passing parameters to the gis.content.search function.

  1. If I type in command parameters  and run the snippet temp_list  =  gis.content.search(query="Boundaries AND owner:MontanaStateLibrary) a list of content is returned. 
  2. However if I build a string, st = 'query=' + '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"',  and do something like this: temp_list  =  gis.content.search(st) an empty list is returned.
    1. In troubleshooting I have copied the printed string, st,  from the interactive window and pasted the text into the gis.content.search()  command which results in a list of content.
  3. As of right now the following code is just a brain dump.  I am using 2 lists to build the parameter string.

    try:
    query_list = ['Boundaries', 'ConservationEasements', 'Geographic Names', 'Hydrography', 'LandCover', 'Mapping Control', 'MontanaMask', 'Montana Managed Areas', 'Montana NAIP', 'NAIP', 'Parcel', 'PLSSS', 'PublicLands', 'Roads', 'Structures', 'Watershed', 'Wetlands']

    item_type_list = list()
    st = 'item_type =' + '"' + 'Feature Layer' + '"'
    item_type_list.append(st)
    st = 'item_type =' + '"' + 'Imagery Layer'# + '"'
    item_type_list.append(st)
    st = 'item_type =' + '"' + 'Map Image Layer'# + '"'
    item_type_list.append(st)
    for q in query_list:
    st = 'query=' + '"' + q + ' AND owner:MontanaStateLibrary' + '"' #+ ', '
    temp_list = gis.content.search(st)

Am I missing something obvious?

arcgis-api-python‌

0 Kudos
14 Replies
JoshuaBixby
MVP Esteemed Contributor

Did you trip my code changes?  Do they work?

0 Kudos
RobertHolliday
New Contributor III

Sorry I did try what you suggested after taking a second closer look at what you suggested.

Screen Capture

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I see what Dan is getting at above, what about:

st = q + ' AND owner:MontanaStateLibrary'
temp_list = gis.content.search(query=st)

RobertHolliday
New Contributor III

Success!  I am not sure I would have ever figured out to enter an unquoted string.  Thanks to both Joshua Bixby and Dan Patterson for the help.

Screen Capture

0 Kudos
RobertHolliday
New Contributor III

Thanks to you both for the help.

####################

Bob Holliday

Montana State Library

rholliday@mt.gov<mailto:rholliday@mt.gov>

0 Kudos