Skip to content

Commit

Permalink
fix(search): ensure no space is inserted between search fields and terms
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-portal

ISSUES CLOSED: #545
  • Loading branch information
jgravois committed Apr 24, 2019
1 parent 3cdaeb9 commit ff90f51
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/arcgis-rest-portal/src/util/SearchQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { IParamBuilder, warn } from "@esri/arcgis-rest-request";
*
* Will search for items matching
* ```
* "owner: Patrick AND (type: "Web Mapping Application" OR type: "Mobile Application" OR type: Application) AND Demo App"
* "owner: Patrick AND (type:"Web Mapping Application" OR type:"Mobile Application" OR type:Application) AND Demo App"
* ```
*/
export class SearchQueryBuilder implements IParamBuilder {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class SearchQueryBuilder implements IParamBuilder {
}

if (field && field !== "*") {
this.q += `${field}: `;
this.q += `${field}:`;
}

return this.commit();
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-portal/test/groups/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("groups", () => {

it("should make a simple, single search request with a builder", done => {
fetchMock.once("*", GroupSearchResponse);
const expectedParam = "Trees AND owner: USFS";
const expectedParam = "Trees AND owner:USFS";
const q = new SearchQueryBuilder()
.match("Trees")
.and()
Expand Down
4 changes: 2 additions & 2 deletions packages/arcgis-rest-portal/test/items/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("search", () => {

it("should make a simple, single search request with a builder", done => {
fetchMock.once("*", SearchResponse);
const expectedParam = "DC AND typekeywords: hubSiteApplication";
const expectedParam = "DC AND typekeywords:hubSiteApplication";
const q = new SearchQueryBuilder()
.match("DC")
.and()
Expand Down Expand Up @@ -108,7 +108,7 @@ describe("search", () => {

it("should pass through other requestOptions at the same time with a builder", done => {
fetchMock.once("*", SearchResponse);
const expectedParam = "DC AND typekeywords: hubSiteApplication";
const expectedParam = "DC AND typekeywords:hubSiteApplication";
const q = new SearchQueryBuilder()
.match("DC")
.and()
Expand Down
20 changes: 10 additions & 10 deletions packages/arcgis-rest-portal/test/util/SearchQueryBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("SearchQueryBuilder", () => {
.match("test")
.in("tags")
.toParam();
expect(query).toEqual("tags: test");
expect(query).toEqual("tags:test");
});

it("should warp multi word search terms in quotes", () => {
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("SearchQueryBuilder", () => {
.in("tags")
.toParam();

expect(query).toEqual("bar AND tags: foo");
expect(query).toEqual("bar AND tags:foo");
});

it("should format a simple range", () => {
Expand All @@ -72,7 +72,7 @@ describe("SearchQueryBuilder", () => {
.to("z")
.in("title")
.toParam();
expect(query).toEqual("title: [a TO z]");
expect(query).toEqual("title:[a TO z]");
});

it("should format a simple group", () => {
Expand All @@ -83,7 +83,7 @@ describe("SearchQueryBuilder", () => {
.in("title")
.endGroup()
.toParam();
expect(query).toEqual("(title: [a TO z])");
expect(query).toEqual("(title:[a TO z])");
});

it("should boost the previous search", () => {
Expand All @@ -110,7 +110,7 @@ describe("SearchQueryBuilder", () => {
.toParam();

expect(query).toEqual(
`created: [${expectedDate1} TO ${expectedDate2}] AND tags: test`
`created:[${expectedDate1} TO ${expectedDate2}] AND tags:test`
);
});

Expand All @@ -135,7 +135,7 @@ describe("SearchQueryBuilder", () => {
.toParam();

expect(query).toEqual(
`owner: fred AND (type: "Web Mapping Application" OR type: "Mobile Application" OR type: Application) AND test`
`owner:fred AND (type:"Web Mapping Application" OR type:"Mobile Application" OR type:Application) AND test`
);
});

Expand All @@ -162,11 +162,11 @@ describe("SearchQueryBuilder", () => {
.in("*");

expect(myAppsQuery.toParam()).toEqual(
`owner: fred AND (type: "Web Mapping Application" OR type: "Mobile Application" OR type: Application)`
`owner:fred AND (type:"Web Mapping Application" OR type:"Mobile Application" OR type:Application)`
);

expect(myTestAppsQuery.toParam()).toEqual(
`owner: fred AND (type: "Web Mapping Application" OR type: "Mobile Application" OR type: Application) AND test`
`owner:fred AND (type:"Web Mapping Application" OR type:"Mobile Application" OR type:Application) AND test`
);
});

Expand Down Expand Up @@ -296,7 +296,7 @@ describe("SearchQueryBuilder", () => {
.toParam();

expect(console.warn).toHaveBeenCalled();
expect(query).toEqual("title: a");
expect(query).toEqual("title:a");
});

it("should not allow .match().from().in(), and warn user", () => {
Expand All @@ -307,7 +307,7 @@ describe("SearchQueryBuilder", () => {
.toParam();

expect(console.warn).toHaveBeenCalled();
expect(query).toEqual("title: test");
expect(query).toEqual("title:test");
});

it("should", () => {
Expand Down

0 comments on commit ff90f51

Please sign in to comment.