Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #50 from swiftype/query-suggesetion-support
Browse files Browse the repository at this point in the history
Query suggestion support
  • Loading branch information
JasonStoltz committed Jan 29, 2019
2 parents cf7d685 + 8fe6bdc commit 26bcf84
Show file tree
Hide file tree
Showing 30 changed files with 229 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist
node_modules
npm-debug.log
yarn-error.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ like https://github.com/github/fetch.
The easiest way to install this client is to simply include the built distribution from the [jsDelivr](https://www.jsdelivr.com/) CDN.

```html
<script src="https://cdn.jsdelivr.net/npm/swiftype-app-search-javascript@2.2.0/dist/swiftype_app_search.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/swiftype-app-search-javascript@2.3.0/dist/swiftype_app_search.umd.js"></script>
```

This will make the client available globally at:
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/click_no_options
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/click.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"tags\":[]}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/click_no_tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/click.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"Cat\",\"document_id\":\"rex-cli\",\"request_id\":\"8b55561954484f13d872728f849ffd22\",\"tags\":[]}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/click_simple
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/click.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"Cat\",\"document_id\":\"rex-cli\",\"request_id\":\"8b55561954484f13d872728f849ffd22\",\"tags\":[\"Cat\"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":0},\"filters\":{\"all\":[{\"license\":\"BSD\"}]},\"facets\":{\"dependencies\":[{\"type\":\"value\",\"size\":3}]},\"analytics\":{\"tags\":[\"Facet-Only\"]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":0},\"filters\":{\"all\":[{\"dependencies\":\"socket.io\"}]},\"facets\":{\"license\":{\"type\":\"value\",\"size\":3}},\"analytics\":{\"tags\":[\"Facet-Only\"]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":0},\"filters\":{},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}]},\"analytics\":{\"tags\":[\"Facet-Only\"]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":0},\"filters\":{\"all\":[{\"dependencies\":\"socket.io\"}]},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}]},\"analytics\":{\"tags\":[\"Facet-Only\"]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":0},\"filters\":{},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}]},\"analytics\":{\"tags\":[\"FromSERP\",\"Disjunctive\"]}}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/multi_search
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/multi_search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"queries\":[{\"query\":\"cat\",\"page\":{\"size\":1}},{\"query\":\"dog\"}]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/multi_search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"queries\":[{\"query\":\"cat\",\"invalid\":\"parameter\"},{\"query\":\"dog\",\"another\":\"parameter\"}]}
Expand Down
31 changes: 31 additions & 0 deletions fixtures/host-2376rb.api.swiftype.com-443/query_suggestion
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST /api/as/v1/engines/node-modules/query_suggestion
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\"}

HTTP/1.1 200 OK
date: Tue, 29 Jan 2019 18:08:51 GMT
content-type: application/json; charset=utf-8
transfer-encoding: chunked
connection: close
vary: Accept-Encoding, Origin
status: 200 OK
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2399
etag: W/"7bbbb718dc1cca4a9911412b186b6b3e"
cache-control: max-age=0, private, must-revalidate
x-request-id: 0750887ae5330b6c0234b6098f4459e8
x-runtime: 0.353357
x-swiftype-frontend-datacenter: dal05
x-swiftype-frontend-node: web01.dal05
x-swiftype-edge-datacenter: dal05
x-swiftype-edge-node: web01.dal05

{"results":{"documents":[{"suggestion":"catwalk"},{"suggestion":"catcher"},{"suggestion":"https://github.com/stuartpb/catcher"},{"suggestion":"categories"},{"suggestion":"categories for"},{"suggestion":"categories for javascript"},{"suggestion":"http://lcfrs.org/cats"},{"suggestion":"cats"},{"suggestion":"https://github.com/luciferous/cats"},{"suggestion":"cat4d"}]},"meta":{"request_id":"0750887ae5330b6c0234b6098f4459e8"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
POST /api/as/v1/engines/node-modules/query_suggestion
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"bad\":\"option\"}

HTTP/1.1 400 Bad Request
date: Tue, 29 Jan 2019 18:11:16 GMT
content-type: application/json; charset=utf-8
transfer-encoding: chunked
connection: close
status: 400 Bad Request
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2399
vary: Origin
cache-control: no-cache
x-request-id: 3dc07facebb356d29cfb26e9e3d50ec0
x-runtime: 0.127407
x-swiftype-frontend-datacenter: dal05
x-swiftype-frontend-node: web01.dal05
x-swiftype-edge-datacenter: dal05
x-swiftype-edge-node: web01.dal05

{"errors":["Options contains invalid key: bad"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST /api/as/v1/engines/node-modules/query_suggestion
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"size\":3,\"types\":{\"documents\":{\"fields\":[\"name\"]}}}

HTTP/1.1 200 OK
date: Tue, 29 Jan 2019 18:14:07 GMT
content-type: application/json; charset=utf-8
transfer-encoding: chunked
connection: close
vary: Accept-Encoding, Origin
status: 200 OK
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2399
etag: W/"b0c17abeee72f6e440978d1c979df21a"
cache-control: max-age=0, private, must-revalidate
x-request-id: 28aa2fbd5ee7e2cbcbb1535c9e85ecfb
x-runtime: 0.314690
x-swiftype-frontend-datacenter: dal05
x-swiftype-frontend-node: web01.dal05
x-swiftype-edge-datacenter: dal05
x-swiftype-edge-node: web01.dal05

{"results":{"documents":[{"suggestion":"catwalk"},{"suggestion":"cats"},{"suggestion":"cat4d"}]},"meta":{"request_id":"28aa2fbd5ee7e2cbcbb1535c9e85ecfb"}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{\"license\":[\"BSD\"]},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{\"license\":\"BSD\"},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}],\"dependencies\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{\"license\":\"BSD\"},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}],\"dependencies\":[{\"type\":\"value\",\"size\":3}]},\"analytics\":{\"tags\":[\"SERP\"]}}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/search_grouped
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"group\":{\"field\":\"license\"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}],\"dependencies\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{\"all\":[{\"license\":\"BSD\"},{\"dependencies\":\"socket.io\"}]},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}],\"dependencies\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{\"all\":[{\"license\":\"BSD\"},{\"dependencies\":\"socket.io\"}]},\"facets\":{\"license\":{\"type\":\"value\",\"size\":3},\"dependencies\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/host-2376rb.api.swiftype.com-443/search_simple
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\",\"page\":{\"size\":1},\"filters\":{},\"facets\":{\"license\":[{\"type\":\"value\",\"size\":3}]}}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/localhost.swiftype.com-3002/localhost_search
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POST /api/as/v1/engines/node-modules/search.json
authorization: Bearer api-hean6g8dmxnm2shqqiag757a
content-type: application/json
x-swiftype-client: swiftype-app-search-javascript
x-swiftype-client-version: 2.2.0
x-swiftype-client-version: 2.3.0
accept: */*
accept-encoding: gzip,deflate
body: {\"query\":\"cat\"}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swiftype-app-search-javascript",
"version": "2.2.0",
"version": "2.3.0",
"description": "Javascript client for the Swiftype App Search Api",
"browser": "dist/swiftype_app_search.umd.js",
"main": "dist/swiftype_app_search.umd.js",
Expand Down
20 changes: 20 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,29 @@ export default class Client {
: `https://${hostIdentifier}.api.swiftype.com/api/as/v1/`;
this.searchPath = `engines/${this.engineName}/search`;
this.multiSearchPath = `engines/${this.engineName}/multi_search`;
this.querySuggestionPath = `engines/${this.engineName}/query_suggestion`;
this.clickPath = `engines/${this.engineName}/click`;
}

/**
* Sends a query suggestion request to the Swiftype App Search Api
*
* @param {String} query String that is used to perform a query suggest.
* @param {Object} options Object used for configuring the query suggest, like 'types' or 'size'
* @returns {Promise<ResultList>} a Promise that returns results, otherwise throws an Error.
*/
querySuggestion(query, options = {}) {
const params = Object.assign({ query: query }, options);

return request(
this.searchKey,
this.apiEndpoint,
this.querySuggestionPath,
params,
this.cacheResponses
).then(handleErrorResponse);
}

/**
* Sends a search request to the Swiftype App Search Api
*
Expand Down
Loading

0 comments on commit 26bcf84

Please sign in to comment.