arcgis-rest-js
arcgis-rest-js copied to clipboard
support group item search?
I'm looking for a function that will search a group's contents, and couldn't find one here. Specifically, I need to hit this endpoint:
https://www.arcgis.com/sharing/rest/content/groups/<groupid>/search
I see I can get the entirety of the group's contents using getGroupContent, but I would actually like to search the contents, with a q query or a categories param or both.
I know what you're thinking. Why not just do a searchItems with a groupid? Well, it turns out these two queries have different results:
https://www.arcgis.com/sharing/rest/content/groups/<groupid>/search?q=<my query here>
https://www.arcgis.com/sharing/rest/search?q=group:<groupid> <my query here>
Here's an example. The first url, groups/<groupid>/search reports 460 total items, while the second, just /search, only has 29.
https://www.arcgis.com/sharing/rest/content/groups/47dd57c9a59d458c86d3d6b978560088/search?categories=["/categories/infrastructure"]&q=type:"Web%20Map"%20-type:"Web%20Mapping%20Application"&sortField=modified&sortOrder=desc&start=1&num=100&f=json
https://www.arcgis.com/sharing/rest/search?categories=["/categories/infrastructure"]&q=group:47dd57c9a59d458c86d3d6b978560088%20type:"Web%20Map"%20-type:"Web%20Mapping%20Application"&sortField=modified&sortOrder=desc&start=1&num=100&f=json
This may be an agol issue, since logically these two searches should return the same results, but since they don't... I'm hoping a searchGroupContent function could be added to this repo. 🙏
AFAIK, you'd be the most likely candidate to add support for a new method like that.
its not the simplest first time contribution someone could make, but its definitely doable. your best bet would probably be adding another wrapper and making some tweaks within genericSearch to account for the additional route.
export function searchGroupContent {
search: string | ISearchOptions | SearchQueryBuilder
): Promise<ISearchResult<IItem>> {
return genericSearch<IItem>(search, "item");
}
https://github.com/Esri/arcgis-rest-js/blob/25778e3e6b16d73cc22a79a7b9bc1c97f4f90ac4/packages/arcgis-rest-portal/src/util/generic-search.ts#L39-L51
if you're interested, but need a little help getting started, don't be shy. I'd be happy to help you get acclimated.
@asizer fwiw I believe we do this in Hub using the main /search endpoint, but we pass in
q=group: b68a9cdeb0ab45b09dd5a5a095c8fb24
since logically these two searches should return the same results, but since they don't...
@asizer the two searches are different. Within a group a group owner/admin can categorize the data within the group. This is only surfaces within the context of the group search. The categories don't apply outside the group. If your UI exposes the categories of the group then you must use the group content search. In this group content search case you would get items categorized within this group as /categories/infrastructure.
Categories can also be defined at the org level. In this case it applies to the categories that the org administrator defined. In the above example using the portal search you would get items that the org categorized as /categories/infrastructure and are also shared to the 47dd57c9a59d458c86d3d6b978560088 group.
I admit that the doc on the portal rest api is very subtle. I passed the feedback on to the rest api search team.
@asizer
I'm finding that if you set the portal property of ISearchOptions to the full group rest path : https://www.arcgis.com/sharing/rest/content/groups/<groupid>/
That seems to do the trick if using searchItems