Skip to content

Commit

Permalink
fix: Make Sort.field optional (#78)
Browse files Browse the repository at this point in the history
- Annotate `field` parameter as optional in docs and typings.
-  Set `field` on class instance only if it is not nil.
  • Loading branch information
Go Yoonho(Enoch) authored and sudo-suhas committed Nov 20, 2018
1 parent 59c951d commit c52ee2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/core/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ const invalidUnitParam = invalidParam(ES_REF_URL, 'unit', UNIT_SET);
* .query(esb.termQuery('user', 'kimchy'))
* .sort(esb.sort('post_date', 'asc'))
*
* @param {string} field The field to sort on
* @param {string=} field The field to sort on.
* If a script is used to specify the sort order, `field` should be omitted.
* @param {string=} order The `order` option can have the following values.
* `asc`, `desc` to sort in ascending, descending order respectively.
*/
class Sort {
// eslint-disable-next-line require-jsdoc
constructor(field, order) {
this._field = field;

this._opts = {};
this._geoPoint = null;
this._script = null;

if (!isNil(field)) this._field = field;
if (!isNil(order)) this.order(order);
}

Expand Down
12 changes: 7 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8258,13 +8258,14 @@ declare namespace esb {
/**
* Allows creating and configuring sort on specified field.
*
* @param {string} field The field to sort on
* @param {string=} field The field to sort on.
* If a script is used to specify the sort order, `field` should be omitted.
* @param {string=} order The `order` option can have the following values.
* `asc`, `desc` to sort in ascending, descending order respectively.
*/
export class Sort {
constructor(field: string, order?: string);

constructor(field?: string, order?: string);
/**
* Set order for sorting. The order defaults to `desc` when sorting on the `_score`,
* and defaults to `asc` when sorting on anything else.
Expand Down Expand Up @@ -8417,11 +8418,12 @@ declare namespace esb {
/**
* Allows creating and configuring sort on specified field.
*
* @param {string} field The field to sort on
* @param {string=} field The field to sort on.
* If a script is used to specify the sort order, `field` should be omitted.
* @param {string=} order The `order` option can have the following values.
* `asc`, `desc` to sort in ascending, descending order respectively.
*/
export function sort(field: string, order?: string): Sort;
export function sort(field?: string, order?: string): Sort;

/**
* A `rescore` request can help to improve precision by reordering just
Expand Down

0 comments on commit c52ee2c

Please sign in to comment.