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
13 changes: 7 additions & 6 deletions src/controllers/searchResult/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ class SearchResultBase {
return this;
});
}
else if (this._request.size && this._request.sort) {
else if (this._request.size && this._request.body.sort) {
const
request = Object.assign({}, this._request, {
action: this._searchAction,
search_after: []
action: this._searchAction
}),
hit = this._response.hits && this._response.hits[this._response.hits.length -1];
hit = this._response.hits[this._response.hits.length -1];

for (const sort of this._request.sort) {
request.body.search_after = [];

for (const sort of this._request.body.sort) {
const key = typeof sort === 'string'
Copy link
Contributor

@Yoann-Abbes Yoann-Abbes Apr 8, 2019

Choose a reason for hiding this comment

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

(nitpicking) maybe adding parentheses here make it more readable

Suggested change
const key = typeof sort === 'string'
const key = (typeof sort === 'string')

? sort
: Object.keys(sort)[0];
const value = key === '_uid'
Copy link
Contributor

Choose a reason for hiding this comment

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

(nitpicking) maybe adding parentheses make it more readable

Suggested change
const value = key === '_uid'
const value = (key === '_uid')

? this._request.collection + '#' + hit._id
: this._get(hit._source, key.split('.'));

request.search_after.push(value);
request.body.search_after.push(value);
}

return _kuzzle.query(request, this._options)
Expand Down
22 changes: 15 additions & 7 deletions test/controllers/searchResult/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ describe('DocumentSearchResult', () => {
request = {
index: 'index',
collection: 'collection',
body: {foo: 'bar'},
body: {
query: {
foo: 'bar'
}
},
controller: 'document',
action: 'search',
};
Expand Down Expand Up @@ -158,7 +162,7 @@ describe('DocumentSearchResult', () => {

beforeEach(() => {
request.size = 2;
request.sort = ['foo', {bar: 'asc'}, {_uid: 'desc'}];
request.body.sort = ['foo', {bar: 'asc'}, {_uid: 'desc'}];

response = {
hits: [
Expand All @@ -181,12 +185,16 @@ describe('DocumentSearchResult', () => {
.be.calledWith({
index: 'index',
collection: 'collection',
body: {foo: 'bar'},
body: {
query: {
foo: 'bar'
},
sort: ['foo', {bar: 'asc'}, {_uid: 'desc'}],
search_after: ['barbar', 2345, 'collection#document2']
},
controller: 'document',
action: 'search',
size: 2,
sort: ['foo', {bar: 'asc'}, {_uid: 'desc'}],
search_after: ['barbar', 2345, 'collection#document2']
size: 2
}, options);
should(res).be.equal(searchResult);
});
Expand Down Expand Up @@ -253,7 +261,7 @@ describe('DocumentSearchResult', () => {
.be.calledWith({
index: 'index',
collection: 'collection',
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'document',
action: 'search',
size: 2,
Expand Down
39 changes: 29 additions & 10 deletions test/controllers/searchResult/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('ProfileSearchResult', () => {
};

request = {
body: {foo: 'bar'},
body: { query: { foo: 'bar'} },
controller: 'security',
action: 'searchProfiles',
};
Expand Down Expand Up @@ -172,12 +172,28 @@ describe('ProfileSearchResult', () => {

beforeEach(() => {
request.size = 2;
request.sort = ['foo', {bar: 'asc'}];
request.body.sort = ['foo', {bar: 'asc'}];

response = {
hits: [
{_id: 'profile1', _version: 1, _source: {policies: ['foo', 'bar'], foo: 'bar', bar: 1234}},
{_id: 'profile2', _version: 3, _source: {policies: ['foo', 'baz'], foo: 'baz', bar: 3456}}
{
_id: 'profile1',
_version: 1,
_source: {
policies: ['foo', 'bar'],
foo: 'bar',
bar: 1234
}
},
{
_id: 'profile2',
_version: 3,
_source: {
policies: ['foo', 'baz'],
foo: 'baz',
bar: 3456
}
}
],
total: 30
};
Expand All @@ -186,18 +202,21 @@ describe('ProfileSearchResult', () => {
kuzzle.query.resolves({result: nextResponse});
});

it('should call security/searchProfiles action with search_after parameter and resolve the current object', () => {
it('should call security/searchProfiles action with search_after \
parameter and resolve the current object', () => {
return searchResult.next()
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: {
sort: ['foo', {bar: 'asc'}],
search_after: ['baz', 3456],
query: { foo: 'bar' }
},
controller: 'security',
action: 'searchProfiles',
size: 2,
sort: ['foo', {bar: 'asc'}],
search_after: ['baz', 3456]
size: 2
}, options);
should(res).be.equal(searchResult);
});
Expand Down Expand Up @@ -268,7 +287,7 @@ describe('ProfileSearchResult', () => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'security',
action: 'searchProfiles',
size: 2,
Expand Down
19 changes: 11 additions & 8 deletions test/controllers/searchResult/specifications.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const
SpecificationsSearchResult = require('../../../src/controllers/searchResult/specifications'),
SpecificationsSearchResult = require(
'../../../src/controllers/searchResult/specifications'),
sinon = require('sinon'),
should = require('should');

Expand All @@ -18,7 +19,7 @@ describe('SpecificationsSearchResult', () => {
};

request = {
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'collection',
action: 'searchSpecifications',
};
Expand Down Expand Up @@ -151,7 +152,7 @@ describe('SpecificationsSearchResult', () => {

beforeEach(() => {
request.size = 2;
request.sort = ['index', {collection: 'asc'}];
request.body.sort = ['index', {collection: 'asc'}];

response = {
hits: [
Expand All @@ -171,12 +172,14 @@ describe('SpecificationsSearchResult', () => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: {
query: { foo: 'bar' },
sort: ['index', {collection: 'asc'}],
search_after: ['index', 'collection2']
},
controller: 'collection',
action: 'searchSpecifications',
size: 2,
sort: ['index', {collection: 'asc'}],
search_after: ['index', 'collection2']
size: 2
}, options);
should(res).be.equal(searchResult);
});
Expand Down Expand Up @@ -237,7 +240,7 @@ describe('SpecificationsSearchResult', () => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'collection',
action: 'searchSpecifications',
size: 2,
Expand Down
16 changes: 9 additions & 7 deletions test/controllers/searchResult/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('UserSearchResult', () => {
};

request = {
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'security',
action: 'searchUsers',
};
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('UserSearchResult', () => {

beforeEach(() => {
request.size = 2;
request.sort = ['name', {bar: 'asc'}];
request.body.sort = ['name', {bar: 'asc'}];

response = {
hits: [
Expand All @@ -196,12 +196,14 @@ describe('UserSearchResult', () => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: {
query: { foo: 'bar' },
sort: ['name', {bar: 'asc'}],
search_after: ['Jane Doe', 3456]
},
controller: 'security',
action: 'searchUsers',
size: 2,
sort: ['name', {bar: 'asc'}],
search_after: ['Jane Doe', 3456]
size: 2
}, options);
should(res).be.equal(searchResult);
});
Expand Down Expand Up @@ -274,7 +276,7 @@ describe('UserSearchResult', () => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
body: {foo: 'bar'},
body: { query: { foo: 'bar' } },
controller: 'security',
action: 'searchUsers',
size: 2,
Expand Down