0

My Cypher query:

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name="000093" AND ALL(x IN tail(nodes(p)) WHERE SINGLE(y IN    tail(nodes(p)) WHERE x=y))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, extract(u IN nodes(p)| u.UserName) AS UserName,length(p), endNode(r[0])
ORDER BY length(p)

i want to avoid having nodes with the same property values in the path, how to avoid them ?

["000093","000090","000096","000097","000107","000091","000089","000093"]
["yunis","gio","Anhar","Jhon","**shakilbit**","xalima","**shakilbit**","yunis"]

so, Order 0000107 and 000089 is being placed by the same username shakilbit, is there any way i can avoid to have those kind of orders in the same path, Thanks! NEO4J.. Very Helping Community as far as i can tell.

Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
MUHAMMAD
  • 61
  • 6

1 Answers1

0

With APOC Procedures, you may want to get your collection as a set (where duplicate values are eliminated) and compare sizes. If duplicates are present, the size of the set will be smaller.

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name="000093" AND ALL(x IN tail(nodes(p)) WHERE SINGLE(y IN    tail(nodes(p)) WHERE x=y))
WITH p, o, r, extract(u IN nodes(p)| u.UserName) AS UserName
// need to make some adjustments since first and last nodes are same
WHERE size(UserName) - 1 = size(apoc.coll.toSet(tail(UserName)))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, UserName, length(p), endNode(r[0])
ORDER BY length(p)

The alternate is to do a repeat of your ALL(x in tail...) WHERE single()... predicate but on the UserName collection (or include this checking in your existing ALL() predicate, though this could be expensive). You may want to PROFILE each and see which is more performant.

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
  • Thanks Man! but i'm having this problem "Unknown function 'apoc.coll.toSet'" and FYI i want to eliminate having such kind of paths wich two orders with same user is shown up! – MUHAMMAD Feb 26 '17 at 03:15
  • I forgot to link to APOC Procedures, link now added. You'll want to scroll to the top and find the link to the latest version *that matches your Neo4j version* (so if you're on Neo4j 3.1.x, you need APOC version 3.1.x, not 3.0.x). To install, you'll need to add the APOC jar to your plugins folder. – InverseFalcon Feb 26 '17 at 03:18
  • i guess there is an issue of compatibility between Neo4j 3.1.0 and APOC 3.1.0.3, as another user of Stackoverflow raised it http://stackoverflow.com/questions/41190251/neo4j-3-1-0-apoc-load-csv-trouble – MUHAMMAD Feb 26 '17 at 03:40
  • To my knowledge that issue is specifically about CSV import/export procedures. Doesn't look like you're using those here. The collection helper functions should work just fine. – InverseFalcon Feb 26 '17 at 03:53
  • i am still having the error "Unknown function 'apoc.coll.toSet'" and i have downloaded the latest version and copied to my plugin folder, i stopped my neo4j server and re-started but nothing still, anyway thanks. – MUHAMMAD Feb 26 '17 at 03:57
  • Make sure you double-check the APOC version. Since APOC is maintaining releases on both the 3.0.x and 3.1.x lines, it can get confusing. Right now, I think they're latest release is on the 3.0.x line, which isn't what you want. You'll want to find the latest release on the 3.1.x line. If you are using the right APOC version, see what APOC functions show up when you run `call dbms.functions()` from the browser. – InverseFalcon Feb 26 '17 at 03:59
  • i have downloaded all the versions one by one and copied to the plugin folder one by one, and nothing seems working. – MUHAMMAD Feb 26 '17 at 04:49
  • Let's see if we can start from the beginning then. What version of Neo4j are you using? – InverseFalcon Feb 26 '17 at 04:53
  • Neo4j Version: 3.1.0 – MUHAMMAD Feb 26 '17 at 05:11
  • may be this blog can help me, i'll flow along: https://indexoutofrange.com/Neo4jStoredProceduresWindows/ – MUHAMMAD Feb 26 '17 at 05:13
  • For Neo 3.1.0, you should be using version 3.1.0.3 of APOC procedures. There should be a `plugins` folder in your Neo4j home directory (for me it's in my `default.graphdb` folder, on Windows it may be under a directory like `Neo4j\ CE\ 3.1.0`). You may need to create the plugins directory if it doesn't exist, and add the APOC jar there and restart. – InverseFalcon Feb 26 '17 at 05:24
  • it was my first step what you suggested with me – MUHAMMAD Feb 26 '17 at 06:28
  • Were you able to get this working? If so, did you figure out what was going on with APOC? – InverseFalcon Feb 27 '17 at 22:09
  • after folowing some steps from the link i have commented before, https://indexoutofrange.com/Neo4jStoredProceduresWindows/ i can use APOC! and your answer solved my original problem thanks. – MUHAMMAD Feb 28 '17 at 04:25