owl-cli 5.28.0 → 5.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -193,6 +193,13 @@ var spec = @spec;
193
193
 
194
194
  var objs = hits.map(function(hit){return hit._source});
195
195
 
196
+
197
+ var countUrl = elasticSearchUrl+"/@projectCode/_count";
198
+
199
+ var ss = HttpUtils.postRaw( countUrl, sndTxt, headers);
200
+ var cr = JSON.parse(ss);
201
+
202
+ var count = result.count;
196
203
  //这里重新从pigeon取了一次数据,做了删除的判断
197
204
  // var ids = hits.map(function(hit){return hit._source.id});
198
205
  // var list = @projectCodeService.getObjects(ids);
@@ -202,7 +209,8 @@ var spec = @spec;
202
209
  var ret = {
203
210
  state:'ok',
204
211
  list:objs,
205
- total:total
212
+ total:total,
213
+ count : count
206
214
  }
207
215
  out.print(JSON.stringify(ret));
208
216
 
@@ -871,28 +871,47 @@ var @projectCodeService = (function (pigeon) {
871
871
  }
872
872
  return filters;
873
873
  },
874
- search: function(m, searchArgs, keyword,from, pageSize, sort, dataSource){
875
- //生成filters
874
+
875
+ buildQuery:function(m,searchArgs,keyword){
876
876
  delete searchArgs.keyword;
877
877
  var filters = [];
878
+ var must_not = [{
879
+ term:{
880
+ del:'T'
881
+ }
882
+ }];
878
883
  for(var k in searchArgs){
884
+ var isNotClause = false;
885
+ if(k.indexOf("!")===0){
886
+ isNotClause = true;
887
+ k = k.substring(1);
888
+ }
879
889
  var v = searchArgs[k];
880
890
  if(typeof v === 'object' && v.type === 'or'){
881
891
  var shouldClauses = [];
882
892
  if(Array.isArray(v.args)){
883
- v.args.forEach(function(q){
884
- var shouldQueries = f.createQuery(q);
885
- if(shouldQueries.length>0){
886
- shouldClauses.push({bool:{filter:shouldQueries}});
887
- }
888
-
889
- });
890
- filters.push({bool:{should:shouldClauses}});
893
+ v.args.forEach(function(q){
894
+ var shouldQueries = f.createQuery(q);
895
+ if(shouldQueries.length>0){
896
+ shouldClauses.push({bool:{filter:shouldQueries}});
897
+ }
898
+
899
+ });
900
+ if(isNotClause){
901
+ must_not.push({bool:{should:shouldClauses}});
902
+ }else{
903
+ filters.push({bool:{should:shouldClauses}});
904
+ }
905
+
891
906
  }
892
907
  else{
893
908
  if(v.args && typeof(v.args)==='object'){
894
909
  var shouldQueries = f.createQuery(v);
895
- filters.push({bool:{filter:shouldQueries}});
910
+ if(isNotClause){
911
+ must_not.push({bool:{should:shouldClauses}});
912
+ }else{
913
+ filters.push({bool:{should:shouldClauses}});
914
+ }
896
915
  }
897
916
  }
898
917
  }
@@ -902,13 +921,21 @@ var @projectCodeService = (function (pigeon) {
902
921
  'gte':v[0],
903
922
  'lte':v[1]
904
923
  }
905
- filters.push({range:range});
924
+ if(isNotClause){
925
+ must_not.push({range:range});
926
+ }else{
927
+ filters.push({range:range});
928
+ }
906
929
  }
907
930
  else if(typeof(v)=='object' && v.type==='terms'){
908
931
  var terms = {};
909
932
  if(v.values){
910
933
  terms[k + ".keyword"] = v.values;
911
- filters.push({terms:terms});
934
+ if(isNotClause){
935
+ must_not.push({terms:terms});
936
+ }else{
937
+ filters.push({terms:terms});
938
+ }
912
939
  }
913
940
  }
914
941
  else{
@@ -916,12 +943,21 @@ var @projectCodeService = (function (pigeon) {
916
943
  if(typeof v == 'string' ){
917
944
  if(v){
918
945
  term[k+".keyword"] = trim('' + v)
919
- filters.push({term:term})
946
+ if(isNotClause){
947
+ must_not.push({term:term});
948
+ }else{
949
+ filters.push({term:term});
950
+ }
951
+
920
952
  }
921
953
  }
922
954
  else if (typeof v == 'number'){
923
955
  term[k] = trim('' + v)
924
- filters.push({term:term})
956
+ if(isNotClause){
957
+ must_not.push({term:term});
958
+ }else{
959
+ filters.push({term:term});
960
+ }
925
961
  }
926
962
  }
927
963
  }
@@ -945,12 +981,6 @@ var @projectCodeService = (function (pigeon) {
945
981
  else{
946
982
  keywordQuery = "*"
947
983
  }
948
-
949
- var effectiveSort = [{owl_createTime:{order:"desc"}}];
950
- if(sort){
951
- effectiveSort = sort;
952
- }
953
-
954
984
  var query = {
955
985
  "query": {
956
986
  "bool": {
@@ -959,17 +989,51 @@ var @projectCodeService = (function (pigeon) {
959
989
  "query":keywordQuery
960
990
  }
961
991
  },
962
- "must_not": {
963
- "match": {
964
- "del": "T"
965
- }
966
- },
992
+ "must_not": must_not,
967
993
  "filter": filters
968
994
  }
969
- },
970
- "from" : from, "size" : pageSize,
971
- sort:effectiveSort
995
+ }
996
+ }
997
+ return query;
998
+ },
999
+
1000
+ count:function(m,searchArgs,keyword,dataSource){
1001
+ var query = f.buildQuery(m,searchArgs,keyword);
1002
+ var elasticSearchUrl = $.getEnv( "elasticSearchUrl" );
1003
+
1004
+ var headers = { "Content-Type": "application/json;charset=utf-8" };
1005
+ var elasticSearchUser = $.getEnv("elasticSearchUser");
1006
+ var elasticSearchPass = $.getEnv("elasticSearchPass");
1007
+ if(elasticSearchUser && elasticSearchPass){
1008
+ var auth =Base64.encode(elasticSearchUser + ":" + elasticSearchPass);
1009
+ var basicAuth = "Basic " + auth;
1010
+ headers["Authorization"] = basicAuth;
1011
+ }
1012
+ var searchUrl = elasticSearchUrl+"/@projectCode/_count";
1013
+ if(dataSource){
1014
+ searchUrl = elasticSearchUrl + "/" + dataSource + "/_count";
1015
+ }
1016
+
1017
+ var sndTxt = JSON.stringify(query);
1018
+ var s = HttpUtils.postRaw( searchUrl, sndTxt, headers);
1019
+ var result = JSON.parse(s);
1020
+ if(result.count){
1021
+ return result.count;
1022
+ }
1023
+ return 0;
1024
+ },
1025
+ search: function(m, searchArgs, keyword,from, pageSize, sort, dataSource){
1026
+ var query = f.buildQuery(m,searchArgs,keyword);
1027
+ var effectiveSort = [{owl_createTime:{order:"desc"}}];
1028
+ if(sort){
1029
+ effectiveSort = sort;
1030
+ } var effectiveSort = [{owl_createTime:{order:"desc"}}];
1031
+ if(sort){
1032
+ effectiveSort = sort;
972
1033
  }
1034
+ query.from = from;
1035
+ query.size = pageSize;
1036
+ query.sort = effectiveSort;
973
1037
 
974
1038
  var elasticSearchUrl = $.getEnv( "elasticSearchUrl" );
975
1039
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owl-cli",
3
- "version": "5.28.0",
3
+ "version": "5.31.0",
4
4
  "main": "index.js",
5
5
  "preferGlobal": true,
6
6
  "bin": {