Merge pull request #4466 from BigFunger/sort-by-score

Sort by score
This commit is contained in:
Jim Unger 2015-08-11 15:35:35 -05:00
commit a96e14b62f
4 changed files with 14 additions and 2 deletions

View file

@ -324,6 +324,7 @@ define(function (require) {
*/
var sortBy = (function () {
if (!_.isArray(sort)) return 'implicit';
else if (sort[0] === '_score') return 'implicit';
else if (sort[0] === timeField) return 'time';
else return 'non-time';
}());
@ -334,6 +335,7 @@ define(function (require) {
}
$scope.updateTime();
if (sort[0] === '_score') segmented.setMaxSegments(1);
segmented.setDirection(sortBy === 'time' ? (sort[1] || 'desc') : 'desc');
segmented.setSize(sortBy === 'time' ? $scope.opts.sampleSize : false);

View file

@ -21,6 +21,7 @@ define(function (require) {
// export a couple methods from the request
this.setDirection = _.bindKey(req, 'setDirection');
this.setSize = _.bindKey(req, 'setSize');
this.setMaxSegments = _.bindKey(req, 'setMaxSegments');
}
return SegmentedHandle;

View file

@ -118,6 +118,15 @@ define(function (require) {
** SegmentedReq specific methods
*********/
/**
* Set the sort total number of segments to emit
*
* @param {number}
*/
SegmentedReq.prototype.setMaxSegments = function (maxSegments) {
this._maxSegments = Math.max(_.parseInt(maxSegments), 1);
};
/**
* Set the sort direction for the request.
*

View file

@ -11,7 +11,7 @@
sorting="sorting">
</thead>
<tbody>
<tr ng-repeat="row in page|limitTo:limit track by row._index+row._type+row._id"
<tr ng-repeat="row in page|limitTo:limit track by row._index+row._type+row._id+row._score"
kbn-table-row="row"
columns="columns"
sorting="sorting"
@ -30,7 +30,7 @@
sorting="sorting">
</thead>
<tbody>
<tr ng-repeat="row in hits|limitTo:limit track by row._index+row._type+row._id"
<tr ng-repeat="row in hits|limitTo:limit track by row._index+row._type+row._id+row._score"
kbn-table-row="row"
columns="columns"
sorting="sorting"