Q: Get the number of nodes in a variable-length relationship Let's say I'm searching a books database with :CATEGORYs and :BOOKs.
I'm trying to find similar books to a current one written by a certain author. :BOOKs have :similar relationships to other books (the direction of the relationship is not relevant), and I would like to look for up to 3 similar chains. Here's my query:
MATCH (currentBook:BOOK {ISBN: {ISBN}})-[:similar*1..3]-(newBook:BOOK {author: {currentAuthor}})
RETURN newBook

Here's the problem:
I need to find out how many similar relationships where used.
And by that, I mean how much the *1..3 actually meant for a specific book. So something like this:
MATCH (currentBook:BOOK {ISBN: {ISBN}})-[sim:similar*1..3]-(newBook:BOOK {author: {currentAuthor}})
SET newBook.simsUsed = AMOUNT_EXPANDED(sim)
RETURN newBook

Here's a (fake) sample of my dataset.

A: SIZE(sim) is probably what you are looking for.
For example, this query will return the length of each path:
MATCH (currentBook:BOOK {ISBN: "978-0446310789"})-[sim:similar*1..3]-(newBook:BOOK {author: "fake"})
RETURN currentBook, newBook, SIZE(sim) AS lth;

You should NOT be setting newBook.simsUsed to that value, though, since the path length to any book depends on which book you started from, and the path length (starting from any particular book) might change over time. In general, you should avoid storing redundant data.
