I have run into a unique situation (bug?). Here is my query that does what 
it is supposed to:

MATCH
   (:Author {name: {author} })-[:WROTE_BOOK]->(b:Book {name_min: {book} 
})-[:HAS_CHAPTER]->(c:Chapter {chapter: {chapter} })-[:HAS_TEXT]->(t:Text),
   (lang:Language {language: {lang} }),
   (version:Version {version_min: {version} })
USING INDEX b:Book(name_min)
OPTIONAL MATCH (user:User {name: {user} })-[user_likes:LIKES]->(c)
WHERE (lang)<-[:IN_LANGUAGE]-(t)-[:IN_VERSION]->(version)
RETURN
   b.name AS book,
   b.name_min AS book_min,
   c.chapter AS chapter,
   t.text AS text,
   c.id AS id,
   count(user_likes) > 0 AS user_likes


Think of this as a system for adding a social layer on top of text books 
where users can like various chapters, books, and/or authors.

What I am doing here is returning the text from a chapter and using an 
OPTIONAL MATCH for the user to see how many :LIKE relationships they have 
to this chapter so I can indicate if they already have liked it. Now this 
is all great, but the running time on this is about 46ms. So I added an 
index hint to the query like:

MATCH
   (:Author {name: {author} })-[:WROTE_BOOK]->(b:Book {name_min: {book} 
})-[:HAS_CHAPTER]->(c:Chapter {chapter: {chapter} })-[:HAS_TEXT]->(t:Text),
   (lang:Language {language: {lang} }),
   (version:Version {version_min: {version} })
USING INDEX b:Book(name_min)
OPTIONAL MATCH (user:User {name: {user} })-[user_likes:LIKES]->(c)
USING INDEX user:User(name)
WHERE (lang)<-[:IN_LANGUAGE]-(t)-[:IN_VERSION]->(version)
RETURN
   b.name AS book,
   b.name_min AS book_min,
   c.chapter AS chapter,
   t.text AS text,
   c.id AS id,
   count(user_likes) > 0 AS user_likes

Now the running time is less than 4ms! Blazing fast! But I only get the 
right b.name, b.name_min, c.chapter, and t.text. The c.id is the wrong and 
the user_likes is always 1+ (assuming they have liked at least one chapter 
somewhere. So what is happening is that the optional match is not using the 
'c' variable from the MATCH above correctly as it seems to be viewing c as 
a wildcard match. What is most interesting is that if it were matching all 
chapters a user like, then count(user_likes) should be 30 in my test case. 
But it is still counting only 1 -- the wrong 1 though.

How does adding the USING INDEX line mess this up? Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to