Java代码实现根据节点属性信息模糊查询节点

Neo4jUtil.java

java 复制代码
@Component
@Slf4j
public class Neo4jUtil {
@Resource
    private Session session;

    public List<Map<String,Object>> getNodeInfoByNodeName(String nodeName) {

        List<Map<String,Object>> dataList = new ArrayList<>();
         if (StrUtil.isBlank(nodeName)) {
             return dataList;
         }

         //拼装查询语句
        String cypherSql = String.format("MATCH (n) where n.name=~ '.*%s.*' RETURN n  ", nodeName);
        Result query = session.query(cypherSql, new HashMap<>(16));

        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("n");
            Long neo4jId = queryNode.getId();
            String[] labels = queryNode.getLabels();
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            Map<String,Object> dataMap = new HashMap<>(5);
            for (Property<String, Object> stringObjectProperty : propertyList) {
                dataMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
                dataMap.put("neo4jId",neo4jId);
                dataMap.put("labels",labels);

            }
            dataList.add(dataMap);
        }
        session.clear();
        return dataList;
    }
}
相关推荐
神仙别闹4 小时前
基于 C++ 实现(控制台)学生成绩管理系统
开发语言·c++
Y幽谷客4 小时前
Python加载本地大模型(Qwen3.5 8B)
python·大模型
Wang's Blog4 小时前
Java 接入Redis: 服务启动停止与后台运行配置
java·服务器·redis
此时不提桶,更待何时5 小时前
01-04-B-垃圾回收面试与生产事故实战
java·jvm·面试
伞伞悦读5 小时前
【第36期】Python 目录与路径详解:pathlib、文件遍历、创建、复制、移动和删除风险
开发语言·python
线上放牧人5 小时前
Windows删除图标缓存
windows·python·pyqt
qq_5470261796 小时前
Python 变量和简单数据类型
python
鹿角片ljp6 小时前
KV Cache 解析
java·算法
智搜广告7 小时前
智搜广告:科技行业AI回答优化公司如何破局
大数据·python·elasticsearch·geo