|
|
|
@ -6,15 +6,22 @@ import com.ruoyi.api.ElasticsearchUtils.builders.ESCreateBuilder; |
|
|
|
import com.ruoyi.api.ElasticsearchUtils.builders.Mappings; |
|
|
|
import com.ruoyi.api.ElasticsearchUtils.impl.ElasticSearchUtilImpl; |
|
|
|
import com.ruoyi.api.domain.ESDao; |
|
|
|
import com.ruoyi.api.domain.ZhyDocApi; |
|
|
|
import com.ruoyi.api.mapper.ZhyDocApiMapper; |
|
|
|
import com.ruoyi.system.domain.ZhyArticle; |
|
|
|
import com.ruoyi.system.mapper.ZhyArticleMapper; |
|
|
|
import org.elasticsearch.search.SearchHits; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* --------------------------------------------------------------------------------------------------------------- <br/> |
|
|
|
@ -34,6 +41,12 @@ public class EsTestController { |
|
|
|
RestClientConfig RestHighLevelClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
ZhyDocApiMapper zhyDocApiMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
ZhyArticleMapper zhyArticleMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private org.elasticsearch.client.RestHighLevelClient client; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@ -46,128 +59,82 @@ public class EsTestController { |
|
|
|
public boolean deleteIndex() throws IOException { |
|
|
|
return elasticSearchUtil.deleteIndex("111"); |
|
|
|
} |
|
|
|
@GetMapping("/estest2") |
|
|
|
@GetMapping("/esQuery2") |
|
|
|
public SearchHits indexCreate2() throws Throwable { |
|
|
|
//还差时间排序,和聚合搜索
|
|
|
|
SearchHits hits = new CustomQueryBuilder.Builder(client) |
|
|
|
.buildAndExecute("111"); |
|
|
|
return hits; |
|
|
|
} |
|
|
|
@GetMapping("/estest") |
|
|
|
public SearchHits indexCreate() throws Throwable { |
|
|
|
@GetMapping("/esQuery/{param}") |
|
|
|
public Map indexCreate(@PathVariable("param")String param) throws Throwable { |
|
|
|
//还差时间排序,和聚合搜索
|
|
|
|
SearchHits nodes = new CustomQueryBuilder.Builder(client) |
|
|
|
.withFuzzyMatch("abstracts",param) |
|
|
|
.buildAndExecute("nodes"); |
|
|
|
SearchHits links = new CustomQueryBuilder.Builder(client) |
|
|
|
.withFuzzyMatch("abstracts",param) |
|
|
|
.buildAndExecute("links"); |
|
|
|
Map map = new HashMap(); |
|
|
|
map.put("nodes",nodes); |
|
|
|
map.put("links",links); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
SearchHits hits = new CustomQueryBuilder.Builder(client) |
|
|
|
.withFuzzyMatch("abstracts","天气") |
|
|
|
.buildAndExecute("111"); |
|
|
|
// if (hits.getHits().length> 0) {
|
|
|
|
// for (SearchHit searchHit : hits) {
|
|
|
|
// Map<String, HighlightField> highlightFields = searchHit.getHighlightFields();
|
|
|
|
// T item = JSON.parseObject(searchHit.getSourceAsString(), clazz);
|
|
|
|
// Field[] fields = clazz.getDeclaredFields();
|
|
|
|
// for (Field field : fields) {
|
|
|
|
// field.setAccessible(true);
|
|
|
|
// if (highlightFields.containsKey(field.getName())) {
|
|
|
|
// try {
|
|
|
|
// field.set(item, highlightFields.get(field.getName()).fragments()[0].toString());
|
|
|
|
// } catch (IllegalAccessException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// list.add(item);
|
|
|
|
// }
|
|
|
|
return hits; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/getHeightLight/{querypream}") |
|
|
|
public void getHeightLight(@PathVariable("querypream")String querypream) { |
|
|
|
System.out.println(querypream); |
|
|
|
} |
|
|
|
@GetMapping("/escreate") |
|
|
|
public SearchHits aa() throws Throwable { |
|
|
|
|
|
|
|
System.out.println("Lucene Version: " + |
|
|
|
org.apache.lucene.util.Version.LATEST); |
|
|
|
System.out.println("Loaded from: " + |
|
|
|
org.apache.lucene.util.Version.class.getProtectionDomain().getCodeSource()); |
|
|
|
|
|
|
|
@GetMapping("/esCreateDoc") |
|
|
|
public SearchHits aa() throws Throwable { |
|
|
|
|
|
|
|
|
|
|
|
//创建文档 这里要注意,有一些不能一起使用,例如浮点型字段不能创建精确查找
|
|
|
|
Mappings mappings = new ESCreateBuilder.Builder() |
|
|
|
.addField("paper_title",ESCreateBuilder.exactSearch) |
|
|
|
// .addField("popularity",ESCreateBuilder.floatType)
|
|
|
|
.addField("id",ESCreateBuilder.floatType) |
|
|
|
.addField("lineId",ESCreateBuilder.floatType) |
|
|
|
.addField("keyWorld1") |
|
|
|
.addField("keyWorld2") |
|
|
|
.addField("paper_url") |
|
|
|
.addField("id") |
|
|
|
.addField("DBid") |
|
|
|
.addField("type") |
|
|
|
.addField("abstracts") |
|
|
|
.addField("authors") |
|
|
|
.addField("author") |
|
|
|
.build(); |
|
|
|
System.out.println(mappings); |
|
|
|
////// //创建索引
|
|
|
|
elasticSearchUtil.createIndex("nodes",mappings); |
|
|
|
elasticSearchUtil.createIndex("links",mappings); |
|
|
|
|
|
|
|
boolean a = elasticSearchUtil.createIndex("111",mappings); |
|
|
|
// System.out.println(mappings);
|
|
|
|
//
|
|
|
|
List<ESDao> bookList = new ArrayList<>(); |
|
|
|
|
|
|
|
ESDao esDao = new ESDao(); |
|
|
|
esDao.id = 1; |
|
|
|
esDao.authors = "菅振宇"; |
|
|
|
esDao.lineId = 1; |
|
|
|
esDao.paper_title = "论文名字测试11111"; |
|
|
|
esDao.paper_url = "adsf/sf/asd"; |
|
|
|
esDao.keyWorld1 = "guanjiazi1"; |
|
|
|
esDao.keyWorld2 = "guanjianzi2"; |
|
|
|
esDao.abstracts = "关键测试部分的摘要娃哈哈大段的iiICv几AV艾师傅为天水电费气象水费海里的生物"; |
|
|
|
bookList.add(esDao); |
|
|
|
|
|
|
|
esDao = new ESDao(); |
|
|
|
esDao.id = 2; |
|
|
|
esDao.authors = "菅振宇"; |
|
|
|
esDao.lineId = 1; |
|
|
|
esDao.paper_title = "论文名字测试22222222"; |
|
|
|
esDao.paper_url = "adsf/sf/asd"; |
|
|
|
esDao.keyWorld1 = "guanjiazi1"; |
|
|
|
esDao.keyWorld2 = "guanjianzi2"; |
|
|
|
esDao.abstracts = "ganraoondjdn天气和天气"; |
|
|
|
bookList.add(esDao); |
|
|
|
|
|
|
|
esDao = new ESDao(); |
|
|
|
esDao.id = 3; |
|
|
|
esDao.authors = "菅振宇"; |
|
|
|
esDao.lineId = 1; |
|
|
|
esDao.paper_title = "论文名字测试3333333333"; |
|
|
|
esDao.paper_url = "adsf/sf/asd"; |
|
|
|
esDao.keyWorld1 = "guanjiazi1"; |
|
|
|
esDao.keyWorld2 = "guanjianzi2"; |
|
|
|
esDao.abstracts = "天空和气体"; |
|
|
|
bookList.add(esDao); |
|
|
|
|
|
|
|
esDao = new ESDao(); |
|
|
|
esDao.id = 4; |
|
|
|
esDao.authors = "菅振宇"; |
|
|
|
esDao.lineId = 1; |
|
|
|
esDao.paper_title = "论文名字测试44444444"; |
|
|
|
esDao.paper_url = "adsf/sf/asd"; |
|
|
|
esDao.keyWorld1 = "guanjiazi1"; |
|
|
|
esDao.keyWorld2 = "guanjianzi2"; |
|
|
|
esDao.abstracts = "天阿斯蒂芬阿萨德覅水电费几点睡觉覅"; |
|
|
|
bookList.add(esDao); |
|
|
|
|
|
|
|
esDao = new ESDao(); |
|
|
|
esDao.id = 5; |
|
|
|
esDao.authors = "菅振宇"; |
|
|
|
esDao.lineId = 1; |
|
|
|
esDao.paper_title = "论文名字测试44444444"; |
|
|
|
esDao.paper_url = "adsf/sf/asd"; |
|
|
|
esDao.keyWorld1 = "guanjiazi1"; |
|
|
|
esDao.keyWorld2 = "guanjianzi2"; |
|
|
|
esDao.abstracts = "nononono没有田也灭有七"; |
|
|
|
bookList.add(esDao); |
|
|
|
|
|
|
|
// System.out.println(bookList);
|
|
|
|
// //向索引中增加记录,强烈建议使用第二种将文档的id和记录的id相关联,这在更新或删除的时候非常方便
|
|
|
|
// elasticSearchUtil.addDocBatch("book5", bookList);
|
|
|
|
elasticSearchUtil.addDocBatch("111", bookList, ESDao.class, "id"); |
|
|
|
List<ZhyDocApi> docList = zhyDocApiMapper.selectAllDoc1(); |
|
|
|
for (int i=0;i<docList.size();i++){ |
|
|
|
String abstracts = docList.get(i).getDocTitle(); |
|
|
|
String id = String.valueOf(docList.get(i).getId()); |
|
|
|
|
|
|
|
ESDao esDao = new ESDao(); |
|
|
|
esDao.id = id; |
|
|
|
esDao.DBid = id; |
|
|
|
esDao.type = "node"; |
|
|
|
esDao.abstracts = abstracts; |
|
|
|
bookList.add(esDao); |
|
|
|
} |
|
|
|
elasticSearchUtil.addDocBatch("nodes", bookList, ESDao.class, "id"); |
|
|
|
|
|
|
|
|
|
|
|
ZhyArticle zhyArticle = new ZhyArticle(); |
|
|
|
List<ZhyArticle> lineList = zhyArticleMapper.selectZhyArticleList(zhyArticle); |
|
|
|
for (int i=0;i<lineList.size();i++){ |
|
|
|
String abstracts = lineList.get(i).getName()+lineList.get(i).getKeywords()+lineList.get(i).getSummary(); |
|
|
|
String id = String.valueOf(lineList.get(i).getId()); |
|
|
|
|
|
|
|
ESDao esDao = new ESDao(); |
|
|
|
esDao.id = id; |
|
|
|
esDao.DBid = id; |
|
|
|
esDao.type = "line"; |
|
|
|
esDao.abstracts = abstracts; |
|
|
|
bookList.add(esDao); |
|
|
|
} |
|
|
|
elasticSearchUtil.addDocBatch("links", bookList, ESDao.class, "id"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|