|
@@ -1,34 +1,31 @@
|
|
|
package com.example.nngkxxdp.elk;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-import cn.hutool.http.HttpRequest;
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
-import com.example.nngkxxdp.dao.ElkDao;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.nngkxxdp.service.ElkService;
|
|
|
+import com.example.nngkxxdp.util.Blank;
|
|
|
+import com.example.nngkxxdp.util.ConstStr;
|
|
|
+import com.example.nngkxxdp.util.SendUtil;
|
|
|
import org.apache.http.HttpHost;
|
|
|
-import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
|
|
-import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
|
|
import org.elasticsearch.action.get.GetRequest;
|
|
|
import org.elasticsearch.action.get.GetResponse;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
-import org.elasticsearch.action.search.SearchRequestBuilder;
|
|
|
-import org.elasticsearch.client.RestClient;
|
|
|
-import org.elasticsearch.index.query.RangeQueryBuilder;
|
|
|
-import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|
|
-import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
+import org.elasticsearch.client.RestClient;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
+import org.elasticsearch.index.query.RangeQueryBuilder;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
-import org.elasticsearch.search.aggregations.*;
|
|
|
+import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
|
+import org.elasticsearch.search.aggregations.BucketOrder;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
-import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
|
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
|
|
import org.elasticsearch.search.sort.ScriptSortBuilder;
|
|
@@ -40,15 +37,12 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.example.nngkxxdp.service.ElkService;
|
|
|
-import com.example.nngkxxdp.util.Blank;
|
|
|
-import com.example.nngkxxdp.util.ConstStr;
|
|
|
-import com.example.nngkxxdp.util.SendUtil;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author Mr.wang
|
|
@@ -80,6 +74,7 @@ public class ElkController {
|
|
|
* 部门字段
|
|
|
*/
|
|
|
private String deptName = "departmentname.keyword";
|
|
|
+ private String domainType = "domain_type";
|
|
|
/**
|
|
|
* 发布时间
|
|
|
*/
|
|
@@ -120,7 +115,7 @@ public class ElkController {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@GetMapping("search")
|
|
|
- public Map<String, Object> search(Integer page, Integer limit, String content, String dept, Integer year, String subject) throws IOException {
|
|
|
+ public Map<String, Object> search(Integer page, Integer limit, String content, String dept, String domain, Integer year, String subject) throws IOException {
|
|
|
if (!Blank.notBlank(page) || !Blank.notBlank(limit)) {
|
|
|
return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
|
|
|
}
|
|
@@ -157,6 +152,13 @@ public class ElkController {
|
|
|
}
|
|
|
list.add(boolQueryBuilder2);
|
|
|
}
|
|
|
+ //搜索领域类型
|
|
|
+ if (Blank.notBlank(domain)) {
|
|
|
+ BoolQueryBuilder boolQueryBuilder2 = new BoolQueryBuilder();
|
|
|
+ List<QueryBuilder> should = boolQueryBuilder2.should();
|
|
|
+ should.add(QueryBuilders.matchQuery(domainType, subject));
|
|
|
+ list.add(boolQueryBuilder2);
|
|
|
+ }
|
|
|
if (Blank.notBlank(year)) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
int currentYear = calendar.get(Calendar.YEAR);
|
|
@@ -356,6 +358,16 @@ public class ElkController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取所有领域
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("domainAll")
|
|
|
+ public Map<String, Object> domainAll() {
|
|
|
+ return SendUtil.send(true, null, elkService.domainAll());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 保存提问信息
|
|
|
*
|
|
|
* @param phone
|