Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Neo4j 3.5仅使用嵌入式API而不使用Cypher的全文搜索_Java_Neo4j_Cypher - Fatal编程技术网

Java Neo4j 3.5仅使用嵌入式API而不使用Cypher的全文搜索

Java Neo4j 3.5仅使用嵌入式API而不使用Cypher的全文搜索,java,neo4j,cypher,Java,Neo4j,Cypher,我在应用程序中使用了新的Neo4j 3.5全文搜索功能。目前,我通过嵌入式API执行Cypher来实现这一点 public Result search(String term, String index) { // The query String cypherQuery = "CALL db.index.fulltext.queryNodes(\"" + index + "\", \"" + term + "\") YIELD node, score\n" +

我在应用程序中使用了新的Neo4j 3.5全文搜索功能。目前,我通过嵌入式API执行Cypher来实现这一点

public Result search(String term, String index) {
    // The query
    String cypherQuery = 
        "CALL db.index.fulltext.queryNodes(\"" + index + "\", \"" + term + "\") YIELD node, score\n" + 
            "RETURN id(node), score";
    // Execute query
    return db.execute(cypherQuery);
}

我认为可以利用这种方法来注入Cypher。有没有办法只使用API执行全文搜索?

为了避免密码注入攻击,您应该将输入传递为,如下所示:

[更新]

注:neo4j正式推荐使用参数。例如,要引用Java驱动程序的Javadoc:

强烈鼓励使用参数,这有助于避免危险的密码 注入攻击并像Neo4j那样提高数据库性能 更频繁地重用查询计划


谢谢这无疑解决了注入漏洞。不过,我想知道是否有一种方法可以通过API来实现这一点,因为这似乎是一种更干净的解决方案,而且由于嵌入式API通常速度更快,因此它还可能具有性能优势。请参阅我的更新。这是官方推荐的方法。
public Result search(String term, String index) {
    // The query 
    String cypherQuery = 
        "CALL db.index.fulltext.queryNodes($index, $term) YIELD node, score\n" + 
        "RETURN id(node), score"; 
    // Execute query
    Map<String, Object> params = new HashMap<>();
    params.put("term", term);
    params.put("index", index);
    return db.execute(cypherQuery, params);
}