Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7167ec2

Browse files
committed
_score and _type options NLPchina#150
1 parent 5b3be8f commit 7167ec2

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/_site/controllers.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce,$
1616

1717
$scope.scrollId = undefined;
1818
$scope.amountDescription = "";
19-
var optionsKey = "essql-options";
19+
var optionsKey = "essql-options-v1";
2020
var fetched = 0;
2121
var total = 0 ;
2222
//checkboxes
@@ -36,7 +36,9 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce,$
3636
scrollSize : 10,
3737
alwaysScroll : false,
3838
isAutoSave : false,
39-
delimiter : ','
39+
delimiter : ',',
40+
showScore : false,
41+
showType : false
4042
}
4143
if (typeof(Storage) !== "undefined") {
4244
options = localStorage.getItem(optionsKey);
@@ -80,7 +82,7 @@ $scope.fetchAll = function(){
8082

8183
$http.get($scope.url + scroll_url + $scope.scrollId)
8284
.success(function(data, status, headers, config) {
83-
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat);
85+
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat,$scope.config.showScore,$scope.config.showType);
8486
updateDescription(handler);
8587
var body = handler.getBody()
8688

@@ -160,7 +162,7 @@ function updateWithScrollIfNeeded (query) {
160162
query = updateWithScrollIfNeeded(query);
161163
$http.post($scope.url + "_sql", query)
162164
.success(function(data, status, headers, config) {
163-
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat);
165+
var handler = ResultHandlerFactory.create(data,$scope.config.isFlat,$scope.config.showScore,$scope.config.showType);
164166
updateDescription(handler);
165167
if(handler.isScroll){
166168
$scope.showResults=true;

src/_site/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ <h4 class="panel-title">
122122
<div class="checkbox">
123123
<label><input type="checkbox" ng-model="config.useOldTable" ng-change="onChangeTablePresnterType()" value="">Old Table</label>
124124
</div>
125+
<div class="checkbox">
126+
<label><input type="checkbox" ng-model="config.showScore" ng-change="onChangeTablePresnterType()" value="">Show Score</label>
127+
</div>
128+
<div class="checkbox">
129+
<label><input type="checkbox" ng-model="config.showType" ng-change="onChangeTablePresnterType()" value="">Show Type</label>
130+
</div>
125131
<div class="checkbox">
126132
<label><input type="checkbox" ng-model="config.alwaysScroll" ng-change="alwatsScrollChanged()" value="">always scroll</label>
127133
</div>

src/_site/query.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Returns the right Result Handler depend
44
on the results */
55
var ResultHandlerFactory = {
6-
"create": function(data,isFlat) {
6+
"create": function(data,isFlat,showScore,showType) {
77
function isSearch(){
88
return "hits" in data
99
}
@@ -16,7 +16,8 @@ var ResultHandlerFactory = {
1616
}
1717

1818
if(isSearch()){
19-
return isAggregation() ? new AggregationQueryResultHandler(data) : new DefaultQueryResultHandler(data,isFlat)
19+
return isAggregation() ? new AggregationQueryResultHandler(data) :
20+
new DefaultQueryResultHandler(data,isFlat,showScore,showType)
2021
}
2122

2223
if(isDelete()){
@@ -35,7 +36,7 @@ var ResultHandlerFactory = {
3536
in case of regular query
3637
(Not aggregation)
3738
*/
38-
var DefaultQueryResultHandler = function(data,isFlat) {
39+
var DefaultQueryResultHandler = function(data,isFlat,showScore,showType) {
3940

4041
// createScheme by traverse hits field
4142
function createScheme() {
@@ -47,6 +48,7 @@ var DefaultQueryResultHandler = function(data,isFlat) {
4748
if(isFlat){
4849
findKeysRecursive(scheme,header,"");
4950
}
51+
5052
else {
5153
for(key in header) {
5254

@@ -57,14 +59,22 @@ var DefaultQueryResultHandler = function(data,isFlat) {
5759
}
5860

5961
}
62+
if(showType){
63+
scheme.push("_type");
64+
}
65+
if(showScore){
66+
scheme.push("_score");
67+
}
6068
return scheme
6169
}
6270

6371

6472
this.data = data
6573
this.head = createScheme()
6674
this.isFlat = isFlat;
67-
this.scrollId = data["_scroll_id"]
75+
this.showScore = showScore;
76+
this.showType = showType;
77+
this.scrollId = data["_scroll_id"];
6878
this.isScroll = this.scrollId!=undefined && this.scrollId!="";
6979
};
7080

@@ -92,6 +102,12 @@ DefaultQueryResultHandler.prototype.getBody = function() {
92102
if(this.isFlat){
93103
row = flatRow(this.head,row);
94104
}
105+
if(this.showType){
106+
row["_type"] = hits[i]._type
107+
}
108+
if(this.showScore){
109+
row["_score"] = hits[i]._score
110+
}
95111
body.push(row)
96112
}
97113
return body

0 commit comments

Comments
 (0)