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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "3.0.0",
"version": "3.0.1",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down
8 changes: 6 additions & 2 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ Collection.prototype.search = function (filters, options, cb) {
*/
Collection.prototype.scroll = function (scrollId, options, filters, cb) {
var
request = {body: {}},
request = {body:{}},
self = this;

if (!scrollId) {
throw new Error('Collection.scroll: scrollId required');
throw new Error('Collection.scroll: scrollId is required');
}

if (!cb) {
Expand All @@ -511,6 +511,10 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
options = {};
}

if (!options.scroll) {
throw new Error('Collection.scroll: scroll is required');
Copy link
Contributor

Choose a reason for hiding this comment

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

scroll parameter is not required to do scroll request (that is only to force refreshing scroll id)

Copy link

@ballinette ballinette Jan 19, 2017

Choose a reason for hiding this comment

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

Hmmm are your sure ? the ES documentation gives always a scroll parameter in its examples:
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-scroll.html

POST  /_search/scroll 
{
    "scroll" : "1m", 
    "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ==" 
}

(but I did not test it without the parameter, so maybe their documentation is not exactly good)

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed together, LGTM

}

options.scrollId = scrollId;

this.kuzzle.callbackRequired('Collection.scroll', cb);
Expand Down
10 changes: 9 additions & 1 deletion src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,14 +1283,22 @@ Kuzzle.prototype.query = function (queryArgs, query, options, cb) {
object.refresh = options.refresh;
}

if (options.from) {
if (typeof options.from !== 'undefined' && options.from !== null) {
object.from = options.from;
}

if (options.size) {
object.size = options.size;
}

if (options.scroll) {
object.scroll = options.scroll;
}

if (options.scrollId) {
object.scrollId = options.scrollId;
}

if (options.metadata) {
Object.keys(options.metadata).forEach(function (meta) {
object.metadata[meta] = options.metadata[meta];
Expand Down
9 changes: 9 additions & 0 deletions src/SearchResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ KuzzleSearchResult.prototype.next = function (cb) {
return;
}

// from and size parameters are not valid for a scroll action
if (options.from) {
delete options.from;
}

if (options.size) {
delete options.size;
}

this.dataCollection.scroll(
options.scrollId,
options,
Expand Down
36 changes: 7 additions & 29 deletions test/kuzzleDataCollection/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ describe('Collection methods', function () {

it('should throw an error if no scrollId is set', () => {
var collection = kuzzle.collection(expectedQuery.collection);
should(() => { collection.scroll(); }).throw('Collection.scroll: scrollId required');
should(() => { collection.scroll(); }).throw('Collection.scroll: scrollId is required');
});

it('should throw an error if no scroll is provided', () => {
var collection = kuzzle.collection(expectedQuery.collection);
should(() => { collection.scroll('scrollId'); }).throw('Collection.scroll: scroll is required');
});

it('should throw an error if no callback is given', () => {
var collection = kuzzle.collection(expectedQuery.collection);
should(() => { collection.scroll('scrollId'); }).throw('Collection.scroll: a callback argument is required for read queries');
should(() => { collection.scroll('scrollId', {scroll: '1m'}); }).throw('Collection.scroll: a callback argument is required for read queries');
});

it('should parse the given parameters', done => {
Expand Down Expand Up @@ -189,33 +194,6 @@ describe('Collection methods', function () {

collection.scroll(scrollId, options, filters, cb);
});

it('should parse the given parameters even if no options is given', done => {
var
queryScrollStub,
collection = kuzzle.collection(expectedQuery.collection),
scrollId = 'scrollId',
cb = () => {
done();
};

queryScrollStub = function (args, query, opts, callback) {
should(args.controller).be.exactly('document');
should(args.action).be.exactly('scroll');
should(opts.scrollId).be.exactly(scrollId);

callback(null, {
result: {
total: 0,
hits: []
}
});
};

kuzzle.query = queryScrollStub;

collection.scroll(scrollId, cb);
});
});

describe('#count', function () {
Expand Down