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;
    }
}
相关推荐
Ray Liang21 分钟前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮36 分钟前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
Java水解36 分钟前
Java 中间件:Dubbo 服务降级(Mock 机制)
java·后端
千寻girling39 分钟前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮4 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽4 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
SimonKing5 小时前
OpenCode AI辅助编程,不一样的编程思路,不写一行代码
java·后端·程序员
FastBean5 小时前
Jackson View Extension Spring Boot Starter
java·后端
Seven976 小时前
剑指offer-79、最⻓不含重复字符的⼦字符串
java