diff --git a/packages/arcgis-rest-portal/src/util/generic-search.ts b/packages/arcgis-rest-portal/src/util/generic-search.ts index 183a8e10d8..7a13c365d8 100644 --- a/packages/arcgis-rest-portal/src/util/generic-search.ts +++ b/packages/arcgis-rest-portal/src/util/generic-search.ts @@ -35,7 +35,7 @@ export function genericSearch( } }; } else { - // searchUserAccess has one (knonw) valid value: "groupMember" + // searchUserAccess has one (known) valid value: "groupMember" options = appendCustomParams( search, [ @@ -45,7 +45,12 @@ export function genericSearch( "sortField", "sortOrder", "searchUserAccess", - "searchUserName" + "searchUserName", + "filter", + "countFields", + "countSize", + "categories", + "categoryFilters" ], { httpMethod: "GET" diff --git a/packages/arcgis-rest-portal/src/util/search.ts b/packages/arcgis-rest-portal/src/util/search.ts index ed18e0a527..2494fbec5e 100644 --- a/packages/arcgis-rest-portal/src/util/search.ts +++ b/packages/arcgis-rest-portal/src/util/search.ts @@ -14,6 +14,22 @@ export interface ISearchOptions extends IRequestOptions, IPagingParams { /** Describes whether order returns in ascending or descending order. The default is ascending. */ sortOrder?: "asc" | "desc"; + + /** A comma-separated list of fields to count. The maximum count fields allowed per request is three. Supported count fields are tags, type, access, contentstatus, and categories. */ + countFields?: string; + + /** The maximum number of field values to count for each `countFields`. The default value is 10, and the maximum number allowed is 200. */ + countSize?: number; + + /** Structured filtering is accomplished by specifying a field name followed by a colon and the term you are searching for with double quotation marks. It allows the passing in of application-level filters based on the context. Use an exact keyword match of the expected value for the specified field. Partially matching the filter keyword will not return meaningful results. */ + filter?: string; + + /** A JSON array or comma-separated list of up to eight org content categories to search items. */ + categories?: string | Array; + + /** A comma-separated list of up to three category terms to search for items that have matching categories. */ + categoryFilters?: string; + [key: string]: any; } diff --git a/packages/arcgis-rest-portal/test/items/search.test.ts b/packages/arcgis-rest-portal/test/items/search.test.ts index a66dab15ea..7021222b54 100644 --- a/packages/arcgis-rest-portal/test/items/search.test.ts +++ b/packages/arcgis-rest-portal/test/items/search.test.ts @@ -82,6 +82,75 @@ describe("search", () => { }); }); + it("should take filter, countFields, countSize and construct the request", (done) => { + fetchMock.once("*", SearchResponse); + + searchItems({ + q: "DC", + countFields: "tags, type", + countSize: 15, + filter: `title:"Some Exact Title"`, + sortOrder: "desc", + foo: "bar" // this one should not end up on the url + }) + .then(() => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://www.arcgis.com/sharing/rest/search?f=json&q=DC&sortOrder=desc&filter=title%3A%22Some%20Exact%20Title%22&countFields=tags%2C%20type&countSize=15" + ); + expect(options.method).toBe("GET"); + done(); + }) + .catch((e) => { + fail(e); + }); + }); + + it("should take categories, categoryFilters and construct the request", (done) => { + fetchMock.once("*", SearchResponse); + + searchItems({ + q: "DC", + categories: "/Region/US,/Forest", + categoryFilters: "ocean", + foo: "bar" // this one should not end up on the url + }) + .then(() => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://www.arcgis.com/sharing/rest/search?f=json&q=DC&categories=%2FRegion%2FUS%2C%2FForest&categoryFilters=ocean" + ); + expect(options.method).toBe("GET"); + done(); + }) + .catch((e) => { + fail(e); + }); + }); + + it("should accept categories as an array", (done) => { + fetchMock.once("*", SearchResponse); + + searchItems({ + q: "Washington", + categories: ["/Categories/Water", "/Categories/Forest"] + }) + .then(() => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://www.arcgis.com/sharing/rest/search?f=json&q=Washington&categories=%2FCategories%2FWater%2C%2FCategories%2FForest" + ); + expect(options.method).toBe("GET"); + done(); + }) + .catch((e) => { + fail(e); + }); + }); + it("should properly handle options for which 0 is a valid value", (done) => { fetchMock.once("*", SearchResponse);