Skip to content

Commit

Permalink
fix(arcgis-rest-portal): add supported search fields (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinr authored Sep 15, 2022
1 parent f207bf1 commit 2be361a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/arcgis-rest-portal/src/util/generic-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function genericSearch<T extends IItem | IGroup | IUser>(
}
};
} else {
// searchUserAccess has one (knonw) valid value: "groupMember"
// searchUserAccess has one (known) valid value: "groupMember"
options = appendCustomParams<ISearchOptions>(
search,
[
Expand All @@ -45,7 +45,12 @@ export function genericSearch<T extends IItem | IGroup | IUser>(
"sortField",
"sortOrder",
"searchUserAccess",
"searchUserName"
"searchUserName",
"filter",
"countFields",
"countSize",
"categories",
"categoryFilters"
],
{
httpMethod: "GET"
Expand Down
16 changes: 16 additions & 0 deletions packages/arcgis-rest-portal/src/util/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;

/** A comma-separated list of up to three category terms to search for items that have matching categories. */
categoryFilters?: string;

[key: string]: any;
}

Expand Down
69 changes: 69 additions & 0 deletions packages/arcgis-rest-portal/test/items/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2be361a

Please sign in to comment.