<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: gis.content.search sort_field doesn't work in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865640#M4402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Laurin,&lt;BR /&gt;I agree with you, the gis.content.search() using a sort_field (sort_order desc or asc) does not work as expected. On the &lt;A href="https://developers.arcgis.com/python/guide/accessing-and-creating-content/"&gt;API example page&lt;/A&gt;&amp;nbsp;(scroll down to the "Searching for content in ArcGIS Online" section), it doesn’t even order it correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I made a simple workaround that will order your result by the number of views as you can see in the screenshots below.&lt;/P&gt;&lt;P&gt;The standard search doesn't order the results:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/469867_Before_A.PNG" /&gt;&lt;/P&gt;&lt;P&gt;After the workaround, the result is sorted by the number of views:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji jive-image image-2 j-img-original" src="https://community.esri.com/legacyfs/online/469877_After.PNG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Oct 2019 17:05:20 GMT</pubDate>
    <dc:creator>Per_Åke_MattiasWallin</dc:creator>
    <dc:date>2019-10-30T17:05:20Z</dc:date>
    <item>
      <title>gis.content.search sort_field doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865638#M4400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using the Python API for arcgis and I'm trying to get information on all our items on arcgis online. However, when I use the gis.content.search() the sort_field option doesn't actually seem to sort the data no matter what I choose. I wrote a test to prove this, and sure enough when choosing to sort by numViews, an item with a lower view count comes before one with a higher view count in the array. Is is not supposed to work this way? Or did I do something wrong? My function looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace; font-weight: normal; font-size: 14px; line-height: 19px; white-space: pre;"&gt;&lt;DIV&gt;&lt;SPAN style="color: #569cd6;"&gt;def&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #dcdcaa;"&gt;getData&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;url&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;username&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;password&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;itemType&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;sortType&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;numResults&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #6a9955;"&gt;#Send&amp;nbsp;creds&amp;nbsp;to&amp;nbsp;ArcGIS&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gis&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;GIS(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;url&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;url,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;username&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;username,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;password&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;password)&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #6a9955;"&gt;#Check&amp;nbsp;if&amp;nbsp;we&amp;nbsp;want&amp;nbsp;to&amp;nbsp;search&amp;nbsp;by&amp;nbsp;item&amp;nbsp;type&amp;nbsp;or&amp;nbsp;if&amp;nbsp;we&amp;nbsp;wanted&amp;nbsp;all&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;itemType.lower()&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;==&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;'all'&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;gis.content.search(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;query&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;sort_field&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;sortType,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;max_items&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;numResults)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #c586c0;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;gis.content.search(&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;query&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;item_type&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;itemType,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;sort_field&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;sortType,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="color: #d4d4d4;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;max_items&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #d4d4d4;"&gt;numResults)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Oct 2019 00:19:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865638#M4400</guid>
      <dc:creator>LaurinMcKenna</dc:creator>
      <dc:date>2019-10-25T00:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: gis.content.search sort_field doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865639#M4401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried changing the sort_order in your query? It can be "asc" or "desc".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2019 16:31:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865639#M4401</guid>
      <dc:creator>KimberlySaballett</dc:creator>
      <dc:date>2019-10-30T16:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: gis.content.search sort_field doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865640#M4402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Laurin,&lt;BR /&gt;I agree with you, the gis.content.search() using a sort_field (sort_order desc or asc) does not work as expected. On the &lt;A href="https://developers.arcgis.com/python/guide/accessing-and-creating-content/"&gt;API example page&lt;/A&gt;&amp;nbsp;(scroll down to the "Searching for content in ArcGIS Online" section), it doesn’t even order it correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I made a simple workaround that will order your result by the number of views as you can see in the screenshots below.&lt;/P&gt;&lt;P&gt;The standard search doesn't order the results:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/469867_Before_A.PNG" /&gt;&lt;/P&gt;&lt;P&gt;After the workaround, the result is sorted by the number of views:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji jive-image image-2 j-img-original" src="https://community.esri.com/legacyfs/online/469877_After.PNG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Oct 2019 17:05:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/gis-content-search-sort-field-doesn-t-work/m-p/865640#M4402</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2019-10-30T17:05:20Z</dc:date>
    </item>
  </channel>
</rss>

