3

I have a problem to pass list of string to my parameter {code}

String request = "START sdg=node:Sfamilly(master = {code}) MATCH t-[CONTAINS_SF]->sdg RETURN count(distinct t) as count"

Map<String, Object> params = new HashMap<String, Object>();
List<String> codes = new ArrayList<String>();
codes.add("1234");
codes.add("12345");
params.put("master", codes);

Result<Map<String, Object>> resultMag = neo4jTemplate.query(request,params);

it appears that my parameters are not considered ?

Any idea ?

I use spring data neo4j rest 2.3.0.M1.

Thanks. Charles.

1 Answer 1

1

First of all, I think you wanted to say

params.put("code", codes); // on line 7

More importantly, it seems to me that passing lists is only supported when querying nodes by ID.

Not sure this is the best possible solution, but it should work. It builds a Lucene query first from your parameters, then passes it into your Neo4j query.

private void yourMethod() {
    String request = "START sdg=node:Sfamilly({luceneQuery}) MATCH t-[CONTAINS_SF]->sdg RETURN count(distinct t) as count";

    Map<String, Object> params = new HashMap<String, Object>();
    List<String> codes = new ArrayList<String>();
    codes.add("1234");
    codes.add("12345");
    params.put("luceneQuery", listToParams("master", codes));

    Result<Map<String, Object>> resultMag = neo4jTemplate.query(request, params);
}

private String listToParams(String paramName, List<String> params) {
    if (params.isEmpty()) {
        throw new IllegalArgumentException("Empty params");
    }

    Iterator<String> paramsIterator = params.iterator();
    StringBuilder builder = new StringBuilder(paramName).append(":").append(paramsIterator.next());

    while (paramsIterator.hasNext()) {
        builder.append(" OR ").append(paramName).append(":").append(paramsIterator.next());
    }

    return builder.toString();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.