public class EsQuery { private static int DEFAULT_SIZE =100; private final Map termFilter;private final Map rangeFilter;private final Map matchFilter;private int size;private String orderBy =null;private String order =null; // query 查询语法, 是否需要 filtered, filter 这两层// 5.x 版本不再需要这两层private boolean isNeedFilterLayer =true; private Integer from; private final Map mustNotTermFilter; private final Map shouldTermFilter;private Integer shouldMatchMinimum; private List includes;private List excludes; public EsQuery() {this.termFilter =new HashMap<>();this.rangeFilter =new HashMap();this.matchFilter =new HashMap();this.mustNotTermFilter =new HashMap<>();this.shouldTermFilter =new HashedMap();this.size = DEFAULT_SIZE;this.includes =new ArrayList<>();this.excludes =new ArrayList<>();} public EsQuery addTermFilter(String key, Object value) {this.termFilter.put(key, value);return this;} public EsQuery addMustNotTermFilter(String key, Object value) {this.mustNotTermFilter.put(key, value);return this;} public EsQuery addAllMustNotTermFilter(Map mustNot) {if (mustNot !=null && !mustNot.isEmpty()) {this.mustNotTermFilter.putAll(mustNot);}return this;} public EsQuery addShouldTermFilter(String key, Object value) {this.shouldTermFilter.put(key, value);return this;} public EsQuery addAllShouldTermFilter(Map should) {if (should !=null && !should.isEmpty()) {this.shouldTermFilter.putAll(should);}return this;} public EsQuery addRangeFilter(String key,long gte,long lte){this.rangeFilter.put(key,new Range(gte, lte));return this;} public EsQuery addMatchFilter(String key, Match value) {this.matchFilter.put(key, value);return this;} public EsQuery addIncludeFields(List includes) {this.includes.addAll(includes);return this;} public EsQuery addExcludeFields(List excludes) {this.excludes.addAll(excludes);return this;}  @Overridepublic String toString() {return toJsonString();} public String toJsonString() {Map finalQuery =new HashMap<>();Map queryMap =new HashMap<>();Map filteredMap =new HashMap<>();Map filterMap =new HashMap<>();Map boolMap =new HashMap<>(); List mustList = obtainTermFilterList(this.termFilter); List mustNotList = obtainTermFilterList(this.mustNotTermFilter); List shouldList = obtainTermFilterList(this.shouldTermFilter); if(!this.rangeFilter.isEmpty()){for(Map.Entry e:this.rangeFilter.entrySet()){Map rangeMap =new HashMap<>();Map rangeEntityMap =new HashMap<>();rangeEntityMap.put(e.getKey(), e.getValue().toMap());rangeMap.put(Constant.range, rangeEntityMap);mustList.add(rangeMap);}} if(!this.matchFilter.isEmpty()){this.matchFilter.forEach((key, match) -> {Map matchEntityMap =new HashMap<>();Map matchMap =new HashMap<>();Map subMatchMap =new HashMap<>();matchEntityMap.put(Constant.query, match.getQuery());matchEntityMap.put(Constant.should_minum, match.getMinimumShouldMatch());matchMap.put(key, matchEntityMap);subMatchMap.put(Constant.match, matchMap);mustList.add(subMatchMap);});} boolMap.put(Constant.must, mustList);if (!mustNotList.isEmpty())boolMap.put(Constant.mustNot, mustNotList);if (!shouldList.isEmpty()) {// 有 minimum_should_match 不带过滤器boolMap.put(Constant.should, shouldList);boolMap.put(Constant.should_minum, shouldMatchMinimum);queryMap.put(Constant.bool, boolMap);}else {if (isNeedFilterLayer) {filterMap.put(Constant.bool, boolMap);filteredMap.put(Constant.filter, filterMap);queryMap.put(Constant.filtered, filteredMap);}else {queryMap.put(Constant.bool, boolMap);}}finalQuery.put(Constant.query, queryMap); Map orderMap =new HashMap<>();Map orderItem =new HashMap<>(); if(order !=null && orderBy !=null){orderItem.put(Constant.order,this.order);orderMap.put(this.orderBy, orderItem);finalQuery.put(Constant.sort, orderMap);} Map source =new HashMap<>();if (!includes.isEmpty()) {source.put(Constant.includes,this.includes);}if (!excludes.isEmpty()) {source.put(Constant.excludes,this.excludes);}if (!source.isEmpty()) {finalQuery.put(Constant.source, source);} finalQuery.put(Constant.size,this.size);if (from !=null) {finalQuery.put(Constant.from, from.intValue());}return JSON.toJSONString(finalQuery);} public List obtainTermFilterList(Map termFilter) {List termFilterList =new ArrayList<>();for (Map.Entry e: termFilter.entrySet()){Map termMap =new HashMap<>();Map itemMap =new HashMap<>();itemMap.put(e.getKey(), e.getValue());if(e.getValue()instanceof List){termMap.put(Constant.terms, itemMap);}else{termMap.put(Constant.term, itemMap);}termFilterList.add(termMap);}return termFilterList;} public String getOrderBy() {return orderBy;} public void setOrderBy(String orderBy) {this.orderBy = orderBy;} public String getOrder() {return order;} public void setOrder(String order) {this.order = order;} public int getSize() {return size;} public void setSize(int size) {this.size = size;} public Integer getFrom() {return from;} public void setFrom(Integer from) {this.from = from;} public Map getTermFilter() {return Collections.unmodifiableMap(termFilter);} public Map getRangeFilter() {return Collections.unmodifiableMap(rangeFilter);} public Map getMustNotTermFilter() {return Collections.unmodifiableMap(mustNotTermFilter);} public Map getShouldTermFilter() {return Collections.unmodifiableMap(shouldTermFilter);} public Map getMatchFilter() {return matchFilter;} public void setShouldMatchMinimum(Integer shouldMatchMinimum) {this.shouldMatchMinimum = shouldMatchMinimum;} public Integer getShouldMatchMinimum() {return shouldMatchMinimum;} public Map getRangeMap(String key) {return Collections.unmodifiableMap(rangeFilter.get(key).toMap());} public List getIncludes() {return Collections.unmodifiableList(includes);} public boolean isNeedFilterLayer() {return isNeedFilterLayer;} public void setNeedFilterLayer(boolean needFilterLayer) {isNeedFilterLayer = needFilterLayer;} @Overridepublic boolean equals(Object o) {// for you to write} @Overridepublic int hashCode() {// for you to write}

java编写字符串连接程序注释_Java 注解自动化处理对应关系实现注释代码化相关推荐

  1. java编写字符串连接程序注释_一种利用JAVA注释支持多行字符串的方法

    从BeetlSql项目将SQL全放在Beetl模板里得到启发,又想到一个比较偏门的用法.以下代码实测通过,详见jSqlBox项目的test\examples\multipleLineSQL\SqlTe ...

  2. 利用java编写网络聊天程序并加密信息

    利用java编写网络聊天程序并加密信息 优化了代码后的地址:https://blog.csdn.net/qq_43483251/article/details/125470514?spm=1001.2 ...

  3. [转载]使用Java编写Palm OS程序的解决方案

    使用Java编写Palm OS程序的解决方案 简介 现在,使用Java语言为 Palm OS编写程序的领域还没有完全统一,并且也有许多程度上的差异,目前,市面上有好几种不同的可用的应用程序接口,每种应 ...

  4. [转载]Java嵌入式开发之一-简介使用Java编写Palm OS程序的解决方案

    Java嵌入式开发之一-简介使用Java编写Palm OS程序的解决方案 现在,使用Java语言为 Palm OS编写程序的领域还没有完全统一,并且也有许多程度上的差异,目前,市面上有好几种不同的可用 ...

  5. [转载]简介使用Java编写Palm OS程序的解决方案(1)

    简介使用Java编写Palm OS程序的解决方案(1) 现在,使用Java语言为 Palm OS编写程序的领域还没有完全统一,并且也有许多程度上的差异,目前,市面上有好几种不同的可用的应用程序接口,每 ...

  6. java中的基本小程序_12个用Java编写基础小程序经典案例(收藏篇)

    原标题:12个用Java编写基础小程序&经典案例(收藏篇) 如果是刚接触或者刚学习java,练习一些基础的算法还是必须的,可以提升思维和语法的使用. 1.输出两个int数中的最大值 impor ...

  7. java application程序_如何Java编写的application程序像exe一样方便shy;的运行

    Java编写的application程序是否能够最终形成一个类似于exe一样的可执行文件,难道就只能用命令行运行??? ---------------------------------------- ...

  8. [转载]简介使用Java编写Palm OS程序的解决方案(2)

    简介使用Java编写Palm OS程序的解决方案(2) 简介 简介使用Java编写Palm OS程序的解决方案(2) 二.Kawt的解决方案 Kawt也是 KVM的一个 Abstract Window ...

  9. java俄罗斯方块程序_使用JAVA编写的俄罗斯方块程序, 具有非常全面的功能.

    Lastsong-Tetris 使用JAVA编写的俄罗斯方块程序, 具有非常全面的功能. 游戏基本规则: 1.打开游戏窗口后, 点击开始按钮进行游戏; 2.每消一行就会增加10分和1消行数,当分数累计 ...

最新文章

  1. mysql select 返回列,是否可以对在mysql SELECT语句中返回列的顺序进行排序?
  2. 面试官:谈谈Redis缓存和MySQL数据一致性问题
  3. python和access哪个实用_access和python学哪个
  4. boost::geometry模块变换多边形的测试程序
  5. primefaces_PrimeFaces:在动态生成的对话框中打开外部页面
  6. c语言switch同时比较多个变量,C语言学习if和switch分支选择结构
  7. 推荐]招商就象谈恋爱
  8. php无限级回复页面如何嵌套,php无限级评论嵌套实现代码
  9. 《统计思维-程序员数学之概率统计》学习笔记
  10. 51单片机蜂鸣器演奏《小苹果》C语言程序,51单片机蜂鸣器播放小星星两只老虎欢乐颂 源程序...
  11. android和iOS平台的崩溃捕获和收集
  12. 【转载】HTML自定义滚动条(仿网易邮箱滚动条)
  13. h5 数字变化_那些H5用到的技术(6)——数字滚动特效
  14. Linux 性能优化全景指南
  15. Multism14安装问题
  16. C语言删除字符串的所有尾部空格
  17. SpringBoot+Mybatis+Mysql+Vue+ElementUi实现一个《流浪猫狗领养救助管理系统》毕业设计(超详细教程)
  18. Python软件编程等级考试三级——20210905
  19. 后缀表达式、中缀表达式
  20. 百思不得姐之立即登录注册模块(五)

热门文章

  1. 现代php中文版,现代PHP
  2. Copy-On-Write COW机制
  3. linux python复制安装,复制一个Python全部环境到另一个环境,python另一个,导出此环境下安装的包...
  4. php绘制频谱图,一步一步教你实现iOS音频频谱动画(二)
  5. tp框架中引入php文件,Laravel框架及ThinkPHP框架超级简单的公共文件引入(保留变量)...
  6. 谷歌浏览器怎么重发请求_Googel 浏览器 模拟发送请求工具--Advanced REST Client
  7. 求逆矩阵计算器_991CN的矩阵运算
  8. 时钟php,php+js液晶时钟
  9. java文件序列化_Java序列化与反序列化,文件操作
  10. 【SSM面向CRUD编程专栏 6】springMVC拦截器、异常处理 jdbcTemplate