I encountered a very strange behaviour with this cypher. It's part of a larger cypher but as of the WITH part it should be enough to look at this last part:
WITH sub1, sub2
MATCH (w1:Word {premium:true, searchterm:sub1})
WITH sub1, sub2, w1
MATCH (w2:Word)
WHERE w2.premium = true and w2.searchterm = sub2
RETURN sub1, w1, w1.searchterm as ws1, sub2, w2, w2.searchterm as ws2
I get the following result:
βββββββββββ€βββββββββββββββββββββββββββββ€ββββββββββ€ββββββββββ€βββββββββββββββββββββββββββββ€ββββββββββ
β"sub1" β"w1" β"ws1" β"sub2" β"w2" β"ws2" β
βββββββββββͺβββββββββββββββββββββββββββββͺββββββββββͺββββββββββͺβββββββββββββββββββββββββββββͺββββββββββ‘
β"ab" β{"count":2,"name":"ab","searβ"ab" β"laderin"β{"name":"Ablader","count":1,β"laderin"β
β βchterm":"ab","language":"de"β β β"searchterm":"ablader","langβ β
β β,"premium":true} β β βuage":"de","premium":true} β β
βββββββββββΌβββββββββββββββββββββββββββββΌββββββββββΌββββββββββΌβββββββββββββββββββββββββββββΌββββββββββ€
β"ablader"β{"name":"Ablader","count":1,β"ablader"β"in" β{"count":2,"name":"ab","searβ"in" β
β β"searchterm":"ablader","langβ β βchterm":"ab","language":"de"β β
β βuage":"de","premium":true} β β β,"premium":true} β β
βββββββββββ΄βββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββ΄βββββββββββββββββββββββββββββ΄ββββββββββ
Problem 1: w2 should not be matched as sub2 is not matching the condition that w2.searchterm = sub2 (both lines)
Problem 2: ws2 is defined as w2.searchterm but is not equal in result (last both columns, both lilnes)
Problem 3: matching nodes with searchterm "laderin" and "in" exists in database but are not displayed as result. (there are just one id away from these mistaken returned nodes)
I can't explain this other than a bug.
Just to be complete, when I output this sub1, sub2 at the beginning, it is this result, and only first and last lines should find matching w1 and w2 nodes.
βββββββββββ€ββββββββββ
β"sub1" β"sub2" β
βββββββββββͺββββββββββ‘
β"ab" β"laderin"β
βββββββββββΌββββββββββ€
β"abl" β"aderin" β
βββββββββββΌββββββββββ€
β"abla" β"derin" β
βββββββββββΌββββββββββ€
β"ablad" β"erin" β
βββββββββββΌββββββββββ€
β"ablade" β"rin" β
βββββββββββΌββββββββββ€
β"ablader"β"in" β
βββββββββββ΄ββββββββββ
Initially I tried with MATCH (w1:Word), (w2:Word) WHERE ... and thought that this cartesian product might be problematic but not. Then I tried to put conditions into {} instead of where-clause - no difference.
And when I set sub1 and sub2 manually, the output is correct - that's really strange:
WITH "ab" as sub1, "laderin" as sub2
MATCH (w1:Word {premium:true, searchterm:sub1})
WITH sub1, sub2, w1
MATCH (w2:Word)
WHERE w2.premium = true and w2.searchterm = sub2
RETURN sub1, w1, w1.searchterm as ws1, sub2, w2, w2.searchterm as ws2
ββββββββ€βββββββββββββββββββββββββββββββ€ββββββ€ββββββββββ€βββββββββββββββββββββββββββββββ€ββββββββββ
β"sub1"β"w1" β"ws1"β"sub2" β"w2" β"ws2" β
ββββββββͺβββββββββββββββββββββββββββββββͺββββββͺββββββββββͺβββββββββββββββββββββββββββββββͺββββββββββ‘
β"ab" β{"count":2,"name":"ab","searchβ"ab" β"laderin"β{"name":"Laderin","count":1,"sβ"laderin"β
β βterm":"ab","language":"de","prβ β βearchterm":"laderin","languageβ β
β βemium":true} β β β":"de","premium":true} β β
ββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββ΄ββββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββββ
This is the result I also expected from the first cypher.
I'm quite annoyed to get a w2.searchterm that differs from searchterm property in w2 in same line of result.
In Profile I often see the expression "cached[w2.searchterm]" - don't know what this mean.
Hope someone can help!
Best,
Reiner