Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/7/controllers/document/search/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Additional query options
| `from` | <pre>number</pre><br/>(`0`) | Offset of the first document to fetch |
| `size` | <pre>number</pre><br/>(`10`) | Maximum number of documents to retrieve per page |
| `scroll` | <pre>string</pre><br/>(`""`) | When set, gets a forward-only cursor having its ttl set to the given value (ie `30s`; cf [elasticsearch time limits](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/common-options.html#time-units)) |
| `verb` | <pre>string</pre> | (HTTP only) Forces the verb of the route |

#### verb

When instantiated with a HTTP protocol object, the SDK uses the POST API by default for this API route.
You can set the `verb` option to `GET` to force the SDK to use the GET API instead.

## Body properties

Expand Down
161 changes: 49 additions & 112 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"babel-loader": "^8.1.0",
"codecov": "^3.6.5",
"codecov": "^3.7.0",
"cucumber": "^6.0.5",
"eslint": "^6.8.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^4.0.0",
"kuzdoc": "^1.2.2",
"lolex": "^6.0.0",
"mocha": "7.1.1",
"mocha": "7.2.0",
"mock-require": "^3.0.3",
"nyc": "^15.0.1",
"proxyquire": "^2.1.3",
Expand Down
15 changes: 11 additions & 4 deletions src/controllers/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,23 @@ class DocumentController extends BaseController {
const request = {
index,
collection,
body,
body: null,
action: 'search',
};

if ( this.kuzzle.protocol.name === 'http'
&& options.verb
&& options.verb.toLowerCase() === 'get'
) {
request.searchBody = body;
}
else {
request.body = body;
}
for (const opt of ['from', 'size', 'scroll']) {
request[opt] = options[opt];
}

const opts = { verb: 'POST', ...options };

const opts = { verb: options.verb || 'POST', ...options };
return this.query(request, opts)
.then(response => ({ response, request, opts }));
}
Expand Down
3 changes: 2 additions & 1 deletion src/protocols/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BaseProtocol = require('./abstract/Base');

class HttpProtocol extends BaseProtocol {
constructor(host, options = {}) {
super(host, options);
super(host, options, 'http');

if (typeof host !== 'string' || host === '') {
throw new Error('host is required');
Expand Down Expand Up @@ -210,6 +210,7 @@ class HttpProtocol extends BaseProtocol {

// inject queryString arguments:
const queryString = [];

for (const key of Object.keys(queryArgs)) {
const value = queryArgs[key];

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const BaseProtocolRealtime = require('./abstract/Realtime');
class WebSocketProtocol extends BaseProtocolRealtime {

constructor(host, options = {}) {
super(host, options);
super(host, options, 'ws');

if (typeof host !== 'string' || host === '') {
throw new Error('host is required');
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/abstract/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const KuzzleEventEmitter = require('../../core/KuzzleEventEmitter');
const PendingRequest = require('./PendingRequest');

class KuzzleAbstractProtocol extends KuzzleEventEmitter {
constructor (host, options = {}) {
constructor (host, options = {}, name = undefined) {
super();

this._pendingRequests = new Map();
this._host = host;
this._name = name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefix properties with an underscore as a convention for private properties. You should add a getter, like what's done for other properties.

const port = parseInt(options.port, 10);
this._port = isNaN(port) ? 7512 : port;
this._ssl = typeof options.sslConnection === 'boolean' ? options.sslConnection : false;
Expand All @@ -31,6 +32,10 @@ class KuzzleAbstractProtocol extends KuzzleEventEmitter {
return this._host;
}

get name () {
return this._name;
}

get port () {
return this._port;
}
Expand Down
Loading