Commit 0bb982f1 by 刘栋

UDI

parent a4de1a85
......@@ -78,33 +78,7 @@
<version>3.7.0</version>
</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 驱动 -->
<dependency>
......@@ -122,13 +96,13 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.12.0</version>
<version>7.12.1</version>
</dependency>
<!-- elasticsearch 的客户端 -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.12.0</version>
<version>7.12.1</version>
</dependency>
<!-- elasticsearch 依赖 2.x 的 log4j -->
<dependency>
......@@ -158,6 +132,11 @@
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.infynova</groupId>
<artifactId>saas-ucpm-api</artifactId>
<version>1.0.0</version>
......
......@@ -99,9 +99,10 @@ public class UdiController {
@ApiOperationSupport(order = 200)
@ApiOperation(value = "searchThree", notes = "searchThree",hidden = true)
@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){
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;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.infynova.common.core.api.ResponseData;
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.TaskHelper;
import com.infynova.udi.service.helper.TaskUploadHelper;
......@@ -40,15 +39,15 @@ public class UdiHelperController {
return ResponseData.ok();
}
@ApiOperationSupport(order = 10000)
@ApiOperation(value = "测试分词器", notes = "测试分词器", hidden = true)
@GetMapping("splitWord")
public ResponseData<String> splitWord(@RequestParam(name = "word") String word) throws Exception {
log.info("splitWord:");
List<String> splitWord = IKAnalyzerSupport.iKSegmenterToList(word);
String result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
return ResponseData.ok(result);
}
// @ApiOperationSupport(order = 10000)
// @ApiOperation(value = "测试分词器", notes = "测试分词器", hidden = true)
// @GetMapping("splitWord")
// public ResponseData<String> splitWord(@RequestParam(name = "word") String word) throws Exception {
// log.info("splitWord:");
// List<String> splitWord = IKAnalyzerSupport.iKSegmenterToList(word);
// String result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
// return ResponseData.ok(result);
// }
@Resource
private TaskUploadHelper taskUploadHelper;
......
......@@ -12,6 +12,8 @@ import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
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.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
......@@ -20,7 +22,10 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.ml.PostDataRequest;
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.util.StopWatch;
......@@ -142,11 +147,32 @@ public class EsSearchHelper {
}
@SneakyThrows
public Map<String, Object> searchThree(String id){
public Map<String, Object> getId(String id){
GetRequest getRequest = new GetRequest(INDEX_NAME, id);
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
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;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
/**
* @author liudong
* 2024/3/14 18:27
* @version 1.0
*/
@Slf4j
public class IKAnalyzerSupport {
/**
* IK分词
* @param target
* @return
*/
public static List<String> iKSegmenterToList(String target) throws Exception {
if (StringUtils.isEmpty(target)){
return new ArrayList<>();
}
List<String> result = new ArrayList<>();
StringReader sr = new StringReader(target);
// false:关闭智能分词 (对分词的精度影响较大)
IKSegmenter ik = new IKSegmenter(sr, true);
Lexeme lex;
while((lex=ik.next())!=null) {
String lexemeText = lex.getLexemeText();
result.add(lexemeText);
}
return result;
}
}
//package com.infynova.udi.service.helper;
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.wltea.analyzer.core.IKSegmenter;
//import org.wltea.analyzer.core.Lexeme;
//
//import java.io.StringReader;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author liudong
// * 2024/3/14 18:27
// * @version 1.0
// */
//@Slf4j
//public class IKAnalyzerSupport {
//
// /**
// * IK分词
// * @param target
// * @return
// */
// public static List<String> iKSegmenterToList(String target) throws Exception {
// if (StringUtils.isEmpty(target)){
// return new ArrayList<>();
// }
// List<String> result = new ArrayList<>();
// StringReader sr = new StringReader(target);
// // false:关闭智能分词 (对分词的精度影响较大)
// IKSegmenter ik = new IKSegmenter(sr, true);
// Lexeme lex;
// while((lex=ik.next())!=null) {
// String lexemeText = lex.getLexemeText();
// result.add(lexemeText);
// }
// return result;
// }
//}
......@@ -283,20 +283,20 @@ public class MatchHelper {
/**
* 对目标进行分词
*/
private String splitWord(String item){
log.info("对目标进行分词");
List<String> splitWord = new ArrayList<>();
String result = item;
try {
splitWord = IKAnalyzerSupport.iKSegmenterToList(item);
result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
log.info("分词结果:{}",result);
} catch (Exception e) {
log.error("分词报错:{}",e.getMessage());
}
return result;
}
// private String splitWord(String item){
// log.info("对目标进行分词");
//
// List<String> splitWord = new ArrayList<>();
// String result = item;
// try {
// splitWord = IKAnalyzerSupport.iKSegmenterToList(item);
// result = splitWord.stream().map(String::valueOf).distinct().collect(Collectors.joining("|")) ;
// log.info("分词结果:{}",result);
// } catch (Exception e) {
// log.error("分词报错:{}",e.getMessage());
// }
// return result;
// }
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