If I need one thing from Portal is there a way to search for it explicitly - at the moment the search result brings back a multitude of things that sound like the item I am searching for (happens to be a layer file) and also includes the actual thing I am looking for.
Ideally I want either 0 or 1 item returns so I know either that search result returned successfully or not.
This is the code I'm using where I am hoping that the "search" should work in the way that I explained above:
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">async</SPAN> Task<SPAN class="operator token"><</SPAN>List<SPAN class="operator token"><</SPAN>AgolLayer<SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">GetAgolLayersAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> numberOfResults<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> search <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> portal <SPAN class="operator token">=</SPAN> ArcGISPortalManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetActivePortal</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
List<SPAN class="operator token"><</SPAN>AgolLayer<SPAN class="operator token">></SPAN> agolLayers <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>AgolLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>portal<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IsSignedOn</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> query <SPAN class="operator token">=</SPAN> PortalQueryParameters<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateForItemsOfTypes</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>PortalItemType<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> PortalItemType<SPAN class="punctuation token">.</SPAN>Layer <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> Module1<SPAN class="punctuation token">.</SPAN>GroupID<SPAN class="punctuation token">,</SPAN> search<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query<SPAN class="punctuation token">.</SPAN>Limit <SPAN class="operator token">=</SPAN> numberOfResults<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Loop until done</SPAN>
<SPAN class="keyword token">var</SPAN> portalItems <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>PortalItem<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>query <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//run the search</SPAN>
PortalQueryResultSet<SPAN class="operator token"><</SPAN>PortalItem<SPAN class="operator token">></SPAN> results <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> portal<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SearchForContentAsync</SPAN><SPAN class="punctuation token">(</SPAN>query<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
portalItems<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddRange</SPAN><SPAN class="punctuation token">(</SPAN>results<SPAN class="punctuation token">.</SPAN>Results<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query <SPAN class="operator token">=</SPAN> results<SPAN class="punctuation token">.</SPAN>NextQueryParameters<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">dynamic</SPAN> item <SPAN class="keyword token">in</SPAN> portalItems<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
AgolLayer agolLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">AgolLayer</SPAN><SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>agolLayer<SPAN class="punctuation token">.</SPAN>IsValidLayer<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
agolLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>agolLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN>
<SPAN class="punctuation token">{</SPAN>
Debug<SPAN class="punctuation token">.</SPAN><SPAN class="token function">WriteLine</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"User not signed in - so layers cannot be retrieved."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> agolLayers<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>