package com.bm.server.serverImpl;
import com.bm.dao.*;
import com.bm.pojo.addr.PlaceOrigin;
import com.bm.pojo.disease.Disease;
import com.bm.pojo.relationship.NodeRelationship;
import com.bm.pojo.sort.AllNode;
import com.bm.pojo.sort.GrapeSort;
import com.bm.pojo.wine.Wine;
import com.bm.server.Neo4jViewActionServer;
import com.google.gson.Gson;
import org.neo4j.driver.Record;
import org.neo4j.driver.StatementResult;
import org.neo4j.driver.Value;
import org.neo4j.driver.types.Node;
import org.neo4j.driver.types.Relationship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
/**
* Created with IntelliJ IDEA.
* User: sx
* Date: 2022/2/9
* Time: 20:17
* Description: java
*/
@Service
public class Neo4jViewActionServerImpl implements Neo4jViewActionServer {
@Resource
private Neo4jGrapeRepository neo4jGrapeRepository;
@Autowired
private Neo4jIndexDao neo4jIndexDao;
@Resource
private Neo4jPlaceOriginRepository neo4jPlaceOriginRepository;
@Resource
private Neo4jDiseaseRepository neo4jDiseaseRepository;
@Resource
private Neo4jWineRepository neo4jWineRepository;
@Override
public String getSearchString(String string) {
String msgString="";
String cql = "match (n:grapeTu)-[r:`产区`]->(p:producingArea) where n.grapeName=~"+"'.*" + string + ".*'"+"or p.name=~"+"'.*" + string + ".*'"+" return n,r,p";
HashMap list = neo4jIndexDao.getList(cql);
if(list.size()<1 || list==null){
msgString= "查无此节点";
}else {
Gson gson = new Gson();
msgString = gson.toJson(list);
}
return msgString;
}
@Override
public List<String> getSort() {
List<String> list = new ArrayList<>();
Iterable<GrapeSort> all = neo4jGrapeRepository.findAll();
for (GrapeSort g:all
) {
list.add(g.getGrapeName());
}
return list;
}
@Override
public List<String> getPlaceOrigin() {
List<String> list = new ArrayList<>();
Iterable<PlaceOrigin> all = neo4jPlaceOriginRepository.findAll();
for (PlaceOrigin p:all
) {
list.add(p.getName());
}
return list;
}
@Override
public List<String> wine() {
List<String> list = new ArrayList<>();
Iterable<Wine> all = neo4jWineRepository.findAll();
for (Wine p:all
) {
list.add(p.getName());
}
return list;
}
@Override
public List<String> disease() {
List<String> list = new ArrayList<>();
Iterable<Disease> all = neo4jDiseaseRepository.findAll();
for (Disease p:all
) {
list.add(p.getName());
}
return list;
}
@Override
public String getsSearching(String string,Integer jingDu) {
double flag=0.0;
//精准度
if(jingDu==1){
flag=0.5;
}else if(jingDu==2){
flag=0.3;
}else {
flag=0.05;
}
List<Record> list=null;
StatementResult indexNode = neo4jIndexDao.getIndexNode(string,flag);
list=indexNode.list();
List<Map<String,String>> nodeNames = new ArrayList<>();
String json="";
if(list.size()>0 && list !=null){
for (Record record:list) {
Value value = record.get(0);
Node node = value.asNode();
Map<String, Object> getNode = node.asMap();
Map<String, String> Map = new HashMap<>();
if(getNode.get("grapeName")!=null){
Map.put("name",(String) getNode.get("grapeName"));
Map.put("label",(String) getNode.get("label"));
Map.put("details",(String) getNode.get("details"));
}else {
Map.put("name",(String) getNode.get("name"));
Map.put("label",(String) getNode.get("label"));
Map.put("details",(String) getNode.get("details"));
}
nodeNames.add(Map);
}
}else {
return null;
}
// 去重
HashSet<AllNode> allNodes = new HashSet<>();
List<AllNode> nodes = new ArrayList<>();
List<NodeRelationship> links = new ArrayList<>();
for (int i=0;i<nodeNames.size();i++){
// 获取检索节点的子节点
List<Record> nodeToRetrieve = neo4jIndexDao.getNodeToRetrieve(nodeNames.get(i));
for (Record r:nodeToRetrieve) {
if(r.size()>1){
Node node1 = r.get(0).asNode();
AllNode start = getNode(node1);
Relationship relationship = r.get(1).asRelationship();
NodeRelationship relationship1 = getRelationship(relationship);
Node node2 = r.get(2).asNode();
AllNode end = getNode(node2);
nodes.add(start);
nodes.add(end);
allNodes.add(start);
allNodes.add(end);
links.add(relationship1);
}else {
Node node1 = r.get(0).asNode();
AllNode start = getNode(node1);
nodes.add(start);
}
}
}
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("nodes",allNodes);
hashMap.put("links",links);
//获取相似度前十的节点
if(nodeNames.size()>=10){
List<Map<String, String>> maps = nodeNames.subList(0, 10);
hashMap.put("list",maps);
}else{
hashMap.put("list",nodeNames);
}
Gson gson = new Gson();
json = gson.toJson(hashMap);//转成字符串
return json;
}
@Override
public String getAllNodes() {
HashMap<String, List<Record>> nodeToRetrieve = neo4jIndexDao.getAll();
HashSet<AllNode> allNodes = new HashSet<>();
List<NodeRelationship> links = new ArrayList<>();
for (Record r:nodeToRetrieve.get("nodes")) {
Node node1 = r.get(0).asNode();
AllNode node = getNode(node1);
if(node.getLabel() ==null && node.getDetails()==null){
continue;
}
allNodes.add(node);
}
for (Record r:nodeToRetrieve.get("links")) {
Relationship relationship = r.get(0).asRelationship();
NodeRelationship relationship1 = getRelationship(relationship);
links.add(relationship1);
}
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("nodes",allNodes);
hashMap.put("links",links);
hashMap.put("list","");
Gson gson = new Gson();
return gson.toJson(hashMap);//转成字符串
}
/**
* 重新整理节点
* @param node
* @return
*/
public AllNode getNode(Node node){
Map<String, Object> nodeMap = node.asMap();
AllNode start = new AllNode();
if(nodeMap.get("grapeName")!=null){
start.setName((String)nodeMap.get("grapeName"));
}else {
start.setName((String)nodeMap.get("name"));
}
start.setDetails((String)nodeMap.get("details"));
start.setId(node.id());
start.setLabel((String)nodeMap.get("label"));
return start;
}
/**
*
* @param relationship
* @return
*/
public NodeRelationship getRelationship(Relationship relationship){
NodeRelationship nodeRelationship = new NodeRelationship();
nodeRe
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
搜索系统是一种用于查找和获取信息的软件系统。它的主要功能包括: 检索信息:搜索系统可以通过关键词、短语或其他查询方式来检索相关信息,帮助用户找到他们需要的内容。 排序和过滤:搜索系统可以根据相关性、时间、地点等条件对搜索结果进行排序和过滤,以便用户更快地找到最相关的信息。 网络爬虫:搜索系统通常会使用网络爬虫来自动地从互联网上获取信息并建立索引,以便能够快速地响应用户的查询。 用户反馈和个性化:一些搜索系统可以根据用户的历史查询、点击行为和其他反馈来提供个性化的搜索结果,以满足用户的特定需求。 多媒体支持:现代搜索系统不仅可以检索文本信息,还可以检索图片、视频、音频等多媒体内容。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JAR.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 48 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
创作小达人
- 粉丝: 278
- 资源: 74
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)