瀏覽代碼

政策问答库,添加领域字段,以及相关查询接口,添加查询所有领域接口

zhoupeng 1 年之前
父節點
當前提交
271c898e11

+ 9 - 3
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/ElkDao.java

@@ -1,11 +1,11 @@
 package com.example.nngkxxdp.dao;
 
-import java.util.List;
-import java.util.Map;
-
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Mr.wang
  * @version 1.0.0
@@ -88,4 +88,10 @@ public interface ElkDao {
     List<Map<String, Object>> getQuestionRemarkPage(@Param("startRows") int startRows, @Param("rows") Integer rows, @Param("phone") String phone, @Param("deptName") String deptName, @Param("remark") String remark);
 
     Integer updateDocumentById(@Param("id") Integer id, @Param("isReply") Integer isReply);
+
+    /**
+     * 获取政策问答库表中,所有的领域类型
+     * @return
+     */
+    List<String> domainAll();
 }

+ 36 - 24
nngkxxdp/src/main/java/com/example/nngkxxdp/elk/ElkController.java

@@ -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

+ 11 - 9
nngkxxdp/src/main/java/com/example/nngkxxdp/service/ElkService.java

@@ -3,33 +3,33 @@ package com.example.nngkxxdp.service;
 import java.util.List;
 import java.util.Map;
 
-/** 
+/**
 * @author Mr.wang
 * @version 1.0.0
 * @date 2021年12月10日 下午4:25:39
-* @Description 
+* @Description
 */
 public interface ElkService {
-	
+
 	/**
 	 * 获取所有部门
 	 * @return
 	 */
 	List<String> deptAll();
-	
+
 	/**
 	 * 获取问题总数
 	 * @return
 	 */
-	Integer getAnswerCount(); 
-	
+	Integer getAnswerCount();
+
 	/**
 	 * 获取部门对应关系
 	 * @param dept
 	 * @return
 	 */
 	List<String> getDeptName(String dept);
-	
+
 	/**
 	 * 保存提问信息
 	 * @param phone
@@ -38,14 +38,14 @@ public interface ElkService {
 	 * @return
 	 */
 	Boolean saveSub(String phone, String remark, String dept);
-	
+
 	/**
 	 * 分页查询提问信息
 	 * @param map
 	 * @return
 	 */
 	Map<String, Object> getPageSub(Map<String, Object> map);
-	
+
 	List<String> getSubDeptAll();
 
 	/**
@@ -81,4 +81,6 @@ public interface ElkService {
 	Map<String, Object> getQuestionRemarkPage(Integer page, Integer limit, String phone, String deptName, String remark);
 
 	Map<String, Object> updateQuestionRemarkById(Integer id, Integer isReply);
+
+	List<String> domainAll();
 }

+ 12 - 7
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/ElkServiceImpl.java

@@ -1,16 +1,16 @@
 package com.example.nngkxxdp.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
+import com.example.nngkxxdp.dao.ElkDao;
+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.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.example.nngkxxdp.dao.ElkDao;
-import com.example.nngkxxdp.service.ElkService;
-import com.example.nngkxxdp.util.SendUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Mr.wang
@@ -77,6 +77,11 @@ public class ElkServiceImpl implements ElkService {
     }
 
     @Override
+    public List<String> domainAll() {
+        return elkDao.domainAll();
+    }
+
+    @Override
     public List<Map<String, Object>> getChildType() {
         List list = new ArrayList();
         List<Map<String, Object>> firstChildType = elkDao.getFirstChildType();

+ 7 - 1
nngkxxdp/src/main/resources/mapper/ElkDao.xml

@@ -140,8 +140,14 @@
         limit #{startRows},#{rows}
     </select>
 
+    <select id="domainAll" resultType="java.lang.String">
+        select distinct(domain_type)
+        from question_article
+        WHERE domain_type IS NOT NULL
+    </select>
+
     <insert id="saveSub">
         insert into question_article_remark(phone, dept_name, remark, is_reply)
         values (#{phone}, #{dept}, #{remark}, 0)
     </insert>
-</mapper>
+</mapper>