cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

How to bind a List<String> with sdn6 java and neo4jClient

guille_rr
Node Link

Hi,
I have to create a query with . . . WHERE labels(e) in [["Lex"],['Alert']] . . .

My code is:

public Collection<ResultFeed> findText(String email, String texto, List<String> label_list) {
		 return this.neo4jClient
				.query("CALL db.index.fulltext.queryNodes('IdxLabels', $texto +'~2')\r\n"
						+ "YIELD node, score\r\n"
						+ "with node as label, score order by score desc limit 100\r\n"
						+ "match (label)<-[:prefLabel]-(c:Concept)\r\n"
						+ "with c, max(score) as maxScore\r\n"
						+ "order by maxScore desc limit 10\r\n"
						+ "call {\r\n"
						+ "match p=(e)-[:RELACIONADO_CON]->(c)\r\n"
						+ "WHERE labels(e) in $label_list \r\n"
. . . 
	.bind(label_list).to("label_list")

and the query is created with:

:params {texto: 'aditivos', label_list: ['Lex', 'Alert'],

but the correct format will be: [["Lex"],['Alert']]

How can I solve this format problem?

Thanks in advance
Regards

3 REPLIES 3

What about changing your WHERE clause to something like:

WHERE ALL(label IN LABELS(e) WHERE label IN $label_list)

and $label_list can be ["label1", "label2"].

Sure, it's a quick fix
works correctly
Thank you Florent
Regards.

You could also provide a list of lists as a parameter:

try (var session = driver.session()) {
	session.run("CREATE (:Thing:Toy), (:Thing:Food), (:Thing:Something)").consume();
}

List<List<String>> labelList = List.of(List.of("Thing", "Toy"), List.of("Thing", "Food"));

Collection<Map<String, Object>> things = neo4jClient.query("MATCH (n:Thing) WHERE labels(n) in $label_list return n")
		.bind(labelList).to("label_list")
		.fetch().all();

assertThat(things).hasSize(2);