Skip to content

Commit 38a2202

Browse files
authored
Merge pull request #446 from maniax89/add_discovery_query_sort_param
[discovery] Add sort parameter for Discovery query
2 parents c230df7 + 99c0daa commit 38a2202

4 files changed

Lines changed: 193 additions & 174 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ var DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
270270
var discovery = new DiscoveryV1({
271271
username: '<username>',
272272
password: '<password>',
273-
version_date: DiscoveryV1.VERSION_DATE_2016_12_15
273+
version_date: DiscoveryV1.VERSION_DATE_2017_04_27
274274
});
275275

276276
discovery.query({
277277
environment_id: '<environment_id>',
278278
collection_id: '<collection_id>',
279-
query:
279+
query: 'my_query'
280280
}, function(err, response) {
281281
if (err) {
282282
console.error(err);

discovery/v1.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function DiscoveryV1(options) {
3131

3232
// Check if 'version_date' was provided
3333
if (typeof this._options.version_date === 'undefined') {
34-
throw new Error('Argument error: version_date was not specified, use DiscoveryV1.VERSION_DATE_2016_12_15');
34+
throw new Error('Argument error: version_date was not specified, use DiscoveryV1.VERSION_DATE_2017_04_27');
3535
}
3636
this._options.qs.version = options.version_date;
3737
}
@@ -46,6 +46,11 @@ DiscoveryV1.URL = 'https://gateway.watsonplatform.net/discovery/api';
4646
* @type {string}
4747
*/
4848
DiscoveryV1.VERSION_DATE_2016_12_15 = '2016-12-15';
49+
/**
50+
* Release exposing the `sort` parameter on the `/query` endpoint
51+
* @type {string}
52+
*/
53+
DiscoveryV1.VERSION_DATE_2017_04_27 = '2017-04-27';
4954

5055
/**
5156
* Return the list of environments
@@ -445,12 +450,13 @@ DiscoveryV1.prototype.deleteDocument = function(params, callback) {
445450
* @param {Object} params
446451
* @param {String} params.environment_id
447452
* @param {string} params.collection_id
448-
* @param {String} [params.filter] A cacheable query that allows you to limit the information returned to exclude anything that isn't related to what you are searching. Filter searches are better for metadata type searches and when you are trying to get a sense of concepts in the dataset.
449453
* @param {String} [params.query] A query search returns all possible results, even when it's not very relevant, with the most relevant documents listed first. Use a query search when you want to find the most relevant search results. Results are scored between 0 and 1, with 1 being an exact match and 0 being not a match at all.
454+
* @param {String} [params.filter] A cacheable query that allows you to limit the information returned to exclude anything that isn't related to what you are searching. Filter searches are better for metadata type searches and when you are trying to get a sense of concepts in the dataset.
450455
* @param {String} [params.aggregation] An aggregation search uses combinations of filters and query search to return an exact answer. Aggregations are useful for building applications, because you can use them to build lists, tables, and time series. For a full list of possible aggregrations, see the Query reference.
451456
* @param {Number} [params.count=10] Number of documents to return
452-
* @param {String} [params.return] A comma separated list of the portion of the document hierarchy to return.
453457
* @param {Number} [params.offset=0] For pagination purposes. Returns additional pages of results. Deep pagination is highly unperformant, and should be avoided.
458+
* @param {String} [params.return] A comma separated list of the portion of the document hierarchy to return.
459+
* @param {String} [params.sort] A comma separated list of fields in the document to sort on. You can optionally specify a sort direction by prefixing the field with - for descending or + for ascending. Ascending is the default sort direction if no prefix is specified.
454460
*/
455461
DiscoveryV1.prototype.query = function(params, callback) {
456462
params = params || {};
@@ -461,7 +467,7 @@ DiscoveryV1.prototype.query = function(params, callback) {
461467
method: 'GET',
462468
json: true,
463469
path: pick(params, ['environment_id', 'collection_id']),
464-
qs: pick(params, ['filter', 'aggregation', 'return', 'count', 'offset', 'query'])
470+
qs: pick(params, ['query', 'filter', 'aggregation', 'count', 'offset', 'return', 'sort'])
465471
},
466472
requiredParams: ['environment_id', 'collection_id'],
467473
defaultOptions: this._options

examples/discovery.v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const discovery = new DiscoveryV1({
1010
// password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
1111
username: 'YOUR USERNAME',
1212
password: 'YOUR PASSWORD',
13-
version_date: DiscoveryV1.VERSION_DATE_2016_12_15
13+
version_date: DiscoveryV1.VERSION_DATE_2017_04_27
1414
});
1515

1616
discovery.getEnvironments({}, function(error, data) {

0 commit comments

Comments
 (0)