Commit 0bb982f1 by 刘栋

UDI

parent a4de1a85
...@@ -78,33 +78,7 @@ ...@@ -78,33 +78,7 @@
<version>3.7.0</version> <version>3.7.0</version>
</dependency> </dependency>
<!-- ikAnalyzer 中文分词器 -->
<dependency>
<groupId>com.janeluo</groupId>
<artifactId>ikanalyzer</artifactId>
<version>2012_u6</version>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- lucene-queryParser 查询分析器模块 -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>7.3.0</version>
</dependency>
<!-- sqlite jdbc 驱动 --> <!-- sqlite jdbc 驱动 -->
<dependency> <dependency>
...@@ -122,13 +96,13 @@ ...@@ -122,13 +96,13 @@
<dependency> <dependency>
<groupId>org.elasticsearch</groupId> <groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId> <artifactId>elasticsearch</artifactId>
<version>7.12.0</version> <version>7.12.1</version>
</dependency> </dependency>
<!-- elasticsearch 的客户端 --> <!-- elasticsearch 的客户端 -->
<dependency> <dependency>
<groupId>org.elasticsearch.client</groupId> <groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId> <artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.12.0</version> <version>7.12.1</version>
</dependency> </dependency>
<!-- elasticsearch 依赖 2.x 的 log4j --> <!-- elasticsearch 依赖 2.x 的 log4j -->
<dependency> <dependency>
...@@ -158,6 +132,11 @@ ...@@ -158,6 +132,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.infynova</groupId> <groupId>com.infynova</groupId>
<artifactId>saas-ucpm-api</artifactId> <artifactId>saas-ucpm-api</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
......
...@@ -99,9 +99,10 @@ public class UdiController { ...@@ -99,9 +99,10 @@ public class UdiController {
@ApiOperationSupport(order = 200) @ApiOperationSupport(order = 200)
@ApiOperation(value = "searchThree", notes = "searchThree",hidden = true) @ApiOperation(value = "searchThree", notes = "searchThree",hidden = true)
@PostMapping("searchThree") @PostMapping("searchThree")
public SearchResult searchThree(@RequestParam(value = "companyName", required = false) String companyName, public Object searchThree(@RequestParam(value = "companyName", required = false) String companyName,
@RequestParam(value = "productFactoryCode", required = false) String productFactoryCode){ @RequestParam(value = "productFactoryCode", required = false) String productFactoryCode){
return redisSearchHelper.searchThree(companyName,productFactoryCode); //return redisSearchHelper.searchThree(companyName,productFactoryCode);
return esSearchHelper.searchThree(companyName,productFactoryCode);
} }
} }
...@@ -5,7 +5,6 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; ...@@ -5,7 +5,6 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.infynova.common.core.api.ResponseData; import com.infynova.common.core.api.ResponseData;
import com.infynova.udi.dto.*; import com.infynova.udi.dto.*;
import com.infynova.udi.service.helper.IKAnalyzerSupport;
import com.infynova.udi.service.helper.MatchHelper; import com.infynova.udi.service.helper.MatchHelper;
import com.infynova.udi.service.helper.TaskHelper; import com.infynova.udi.service.helper.TaskHelper;
import com.infynova.udi.service.helper.TaskUploadHelper; import com.infynova.udi.service.helper.TaskUploadHelper;
...@@ -40,15 +39,15 @@ public class UdiHelperController { ...@@ -40,15 +39,15 @@ public class UdiHelperController {
return ResponseData.ok(); return ResponseData.ok();
} }
@ApiOperationSupport(order = 10000) // @ApiOperationSupport(order = 10000)
@ApiOperation(value = "测试分词器", notes = "测试分词器", hidden = true) // @ApiOperation(value = "测试分词器", notes = "测试分词器", hidden = true)
@GetMapping("splitWord") // @GetMapping("splitWord")
public ResponseData<String> splitWord(@RequestParam(name = "word") String word) throws Exception { // public ResponseData<String> splitWord(@RequestParam(name = "word") String word) throws Exception {
log.info("splitWord:"); // log.info("splitWord:");
List<String> splitWord = IKAnalyzerSupport.iKSegmenterToList(word); // List<String> splitWord = IKAnalyzerSupport.iKSegmenterToList(word);
String result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ; // String result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
return ResponseData.ok(result); // return ResponseData.ok(result);
} // }
@Resource @Resource
private TaskUploadHelper taskUploadHelper; private TaskUploadHelper taskUploadHelper;
......
...@@ -12,6 +12,8 @@ import org.elasticsearch.action.bulk.BulkResponse; ...@@ -12,6 +12,8 @@ import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.action.update.UpdateResponse;
...@@ -20,7 +22,10 @@ import org.elasticsearch.client.RestClient; ...@@ -20,7 +22,10 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.ml.PostDataRequest;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
...@@ -142,11 +147,32 @@ public class EsSearchHelper { ...@@ -142,11 +147,32 @@ public class EsSearchHelper {
} }
@SneakyThrows @SneakyThrows
public Map<String, Object> searchThree(String id){ public Map<String, Object> getId(String id){
GetRequest getRequest = new GetRequest(INDEX_NAME, id); GetRequest getRequest = new GetRequest(INDEX_NAME, id);
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
return getResponse.getSourceAsMap(); return getResponse.getSourceAsMap();
} }
@SneakyThrows
public Object searchThree(String companyName,String productFactoryCode){
SearchRequest searchRequest = new SearchRequest(INDEX_NAME);
// BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
// .must(new MatchPhraseQueryBuilder("companyName", companyName))
// .must(new MatchPhraseQueryBuilder("productFactoryCode", productFactoryCode));
// 构建查询条件
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.should(new MatchQueryBuilder("companyName", companyName))
.should(new TermQueryBuilder("companyName.keyword", companyName))
.should(new MatchQueryBuilder("productFactoryCode", productFactoryCode))
.should(new TermQueryBuilder("productFactoryCode.keyword", productFactoryCode));
// 构建搜索源
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(boolQueryBuilder);
// 设置搜索请求的源
searchRequest.source(searchSourceBuilder);
// 执行搜索
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
return searchResponse;
}
} }
package com.infynova.udi.service.helper; //package com.infynova.udi.service.helper;
//
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.wltea.analyzer.core.IKSegmenter; //import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme; //import org.wltea.analyzer.core.Lexeme;
//
import java.io.StringReader; //import java.io.StringReader;
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
/** ///**
* @author liudong // * @author liudong
* 2024/3/14 18:27 // * 2024/3/14 18:27
* @version 1.0 // * @version 1.0
*/ // */
@Slf4j //@Slf4j
public class IKAnalyzerSupport { //public class IKAnalyzerSupport {
//
/** // /**
* IK分词 // * IK分词
* @param target // * @param target
* @return // * @return
*/ // */
public static List<String> iKSegmenterToList(String target) throws Exception { // public static List<String> iKSegmenterToList(String target) throws Exception {
if (StringUtils.isEmpty(target)){ // if (StringUtils.isEmpty(target)){
return new ArrayList<>(); // return new ArrayList<>();
} // }
List<String> result = new ArrayList<>(); // List<String> result = new ArrayList<>();
StringReader sr = new StringReader(target); // StringReader sr = new StringReader(target);
// false:关闭智能分词 (对分词的精度影响较大) // // false:关闭智能分词 (对分词的精度影响较大)
IKSegmenter ik = new IKSegmenter(sr, true); // IKSegmenter ik = new IKSegmenter(sr, true);
Lexeme lex; // Lexeme lex;
while((lex=ik.next())!=null) { // while((lex=ik.next())!=null) {
String lexemeText = lex.getLexemeText(); // String lexemeText = lex.getLexemeText();
result.add(lexemeText); // result.add(lexemeText);
} // }
return result; // return result;
} // }
} //}
...@@ -283,20 +283,20 @@ public class MatchHelper { ...@@ -283,20 +283,20 @@ public class MatchHelper {
/** /**
* 对目标进行分词 * 对目标进行分词
*/ */
private String splitWord(String item){ // private String splitWord(String item){
log.info("对目标进行分词"); // log.info("对目标进行分词");
//
List<String> splitWord = new ArrayList<>(); // List<String> splitWord = new ArrayList<>();
String result = item; // String result = item;
try { // try {
splitWord = IKAnalyzerSupport.iKSegmenterToList(item); // splitWord = IKAnalyzerSupport.iKSegmenterToList(item);
result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ; // result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
log.info("分词结果:{}",result); // log.info("分词结果:{}",result);
} catch (Exception e) { // } catch (Exception e) {
log.error("分词报错:{}",e.getMessage()); // log.error("分词报错:{}",e.getMessage());
} // }
return result; // return result;
} // }
private final BigDecimal RATE = new BigDecimal("0.25"); private final BigDecimal RATE = new BigDecimal("0.25");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment