Przeglądaj źródła

智能搜索,阶段2;结合界面,增加限制条件,多检索内容条件组装

周壕 9 miesięcy temu
rodzic
commit
a246baf436

+ 13 - 0
src/main/java/com/bowintek/practice/controller/EsQueryController.java

@@ -8,8 +8,10 @@ import com.bowintek.practice.mapper.SrTempDataMapper;
 import com.bowintek.practice.model.SrSaerchtemp;
 import com.bowintek.practice.model.SrTempData;
 import com.bowintek.practice.services.service.*;
+import com.bowintek.practice.util.StringUtils;
 import com.bowintek.practice.vo.Analyze.ComparisonResult;
 import com.bowintek.practice.vo.Analyze.EsQueryModel;
+import com.bowintek.practice.vo.Analyze.EsQueryText;
 import com.bowintek.practice.vo.SaerchtempVo;
 import com.bowintek.practice.vo.system.RoleModel;
 import com.bowintek.practice.vo.temp.GenSqlStringResult;
@@ -30,13 +32,24 @@ import java.util.Map;
 public class EsQueryController {
     @Autowired
     private EsQueryService esQueryService;
+    @Autowired
+    private QueryLogService queryLogService;
+    @Autowired
+    private AccountService accountService;
 
     @PostMapping("/Query")
     public BaseResponse getQuery(@RequestBody EsQueryModel model) {
+        //在es查询并返回结果
         Map<String, Object> results = esQueryService.query(model.getQueryList(),
                 model.getLimiters(),
                 model.getPage(),
                 model.getLimit());
+        //保存查询字符串,查询历史统计
+        for(EsQueryText queryText : model.getQueryList()){
+            if(!StringUtils.IsNullEmpty(queryText.getKeyString()))
+                queryLogService.save(queryText.getKeyString(), accountService.getLoginUserID());
+        }
+
         return RespGenerstor.success(results);
     }
 }

+ 7 - 0
src/main/java/com/bowintek/practice/services/impl/EsQueryServiceImpl.java

@@ -1,6 +1,7 @@
 package com.bowintek.practice.services.impl;
 
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.FieldValue;
 import co.elastic.clients.elasticsearch._types.mapping.Property;
 import co.elastic.clients.elasticsearch._types.mapping.TextProperty;
 import co.elastic.clients.elasticsearch._types.query_dsl.*;
@@ -266,6 +267,12 @@ public class EsQueryServiceImpl implements EsQueryService {
             query = RangeQuery.of(q->q.field(fieldString).lte(JsonData.of(value)))._toQuery();
         else if(opreation.equals("等于"))
             query = TermQuery.of(q->q.field(fieldString).value(value))._toQuery();
+        else if(opreation.equals("包括IN")) {
+            String[] ins = value.split(",");
+            List<FieldValue> fls = new ArrayList<>();
+            for(String inString : ins) fls.add(FieldValue.of(inString));
+            query = TermsQuery.of(q -> q.field(fieldString).terms(s -> s.value(fls)))._toQuery();
+        }
         return query;
     }
 

+ 10 - 6
vue/src/views/esdomain/index.vue

@@ -31,14 +31,15 @@
         <a-col :span="24" class="query-row">
           <div class="col-title"></div>
           <a-select v-model:value="formState.defaultField" :options="fieldList" class="operTexts"></a-select>
-          <a-input v-model:value="formState.defaultKeyString" style="width: 285px"></a-input>
+          <!--AutoComplete继承至vue-->
+          <QueryHistoryComplete v-model:value="formState.defaultKeyString" style="width: 285px"></QueryHistoryComplete>
           <img src="~@/assets/images/add.png" @click="addQuery"/>
         </a-col>
         <a-col :span="24" class="query-row" v-for="(it,index) in queryList">
           <div class="col-title"></div>
           <!--a-select v-model:value="it.oper" :options="operTexts" class="operTexts"></a-select-->
           <a-select v-model:value="it.field" :options="fieldList" class="operTexts"></a-select>
-          <a-input v-model:value="it.keyString" style="width: 285px"></a-input>
+          <QueryHistoryComplete v-model:value="it.keyString" style="width: 285px"></QueryHistoryComplete>
           <img src="~@/assets/images/sub.png" @click="onDelete(index)"/>
         </a-col>
 
@@ -46,7 +47,7 @@
       <a-row :gutter="24">
         <a-col :span="24" class="query-row">
           <div class="col-title"></div>
-          <a-button type="primary" html-type="submit" @click="onQuery">查询</a-button>
+          <a-button type="primary" html-type="submit">查询</a-button>
           <a-button style="margin: 0 8px" @click="() => {formRef.resetFields();}">重置</a-button>
         </a-col>
       </a-row>
@@ -62,10 +63,11 @@ import {DownOutlined, UpOutlined} from "@ant-design/icons-vue";
 import type {FormInstance, SelectProps} from "ant-design-vue";
 import {useTabsViewStore} from "@/store/modules/tabsView";
 import {save} from "@/api/common";
+import QueryHistoryComplete from '@/components/basic/querylog/history-complete.vue'
 
 export default defineComponent({
   name: 'domainESIndex',
-  components: {DownOutlined, UpOutlined},
+  components: {DownOutlined, UpOutlined, QueryHistoryComplete},
   setup() {
     const tabsViewStore = useTabsViewStore();
     const route = useRoute();
@@ -91,7 +93,8 @@ export default defineComponent({
     const fieldList = [
       {value: '', label: '不限'},
       {value: 'well_id', label: '井号'},
-      {value: 'well_common_name', label: '井名'}
+      {value: 'well_common_name', label: '井名'},
+      {value: 'historys.testing_name', label: '测试'}
     ] as SelectProps['options'];
 
     const onQuery = () => {
@@ -110,9 +113,10 @@ export default defineComponent({
       //限定条件写入
       //{"fieldName":"开钻日期", "fields":["spud_date"],"opreation":"大于","value":"2022-03-28"}
       queryObject.limiters.push({ fields:["well_common_name.keyword"], opreation:'等于', value:formState.well_common_name });
+      //多个值测试,如 组织单位 in 哪些值
+      queryObject.limiters.push({ fields:["well_type.keyword"], opreation:'包括IN', value:'直井' });
 
       console.log(queryObject);
-
       save('esquery/Query', queryObject).then(result => {
         console.log(result);
       });