Neo4j - does not know how to improve the encryption request

advertisements

I have this query returning very fast, 0.5 seconds and returning all 303 records expected. Note: "Woka" here means "Book".

MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)<-[s:AUTHORED]-(a:Author),
(l:Language)-[t:USED]->(w:Woka)-[u:INCLUDED]->(b:Bisac)
WHERE (a.author_name = 'Camus, Albert')
RETURN w.woka_id as woka_id, p.publisher_name as publisher_name, w.woka_title as woka_title, a.author_name as author_name, l.language_name as language_name, b.bisac_code as bisac_code, b.bisac_value as bisac_value
ORDER BY woka_id;

And I want to add more info, a description for example. I have the Description nodes created and the relationships created, were exists, between Language and Description and Description and Book (Woka). The query below returns all descriptions as null, but only for 60 records instead of 303. This is because not all the books have a description. Execution time is still ok, 0.3 seconds.

MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)<-[s:AUTHORED]-(a:Author),
(l:Language)-[t:USED]->(w:Woka), (b:Bisac)<-[u:INCLUDED]-(w:Woka),
(d:Description)-[v:HAS_DESCRIPTION]-(w)
WHERE (a.author_name = 'Camus, Albert')
RETURN w.woka_id as woka_id, p.publisher_name as publisher_name, w.woka_title as woka_title, a.author_name as author_name, l.language_name as language_name, b.bisac_code as bisac_code, b.bisac_value as bisac_value, d.description as description
ORDER BY woka_id;

However I know that some of the records left out from the result set, the difference between 50 and 303 does have a description. I build another query using OPTIONAL, but this one (shown below) never returns, runs for ever.

MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)<-[s:AUTHORED]-(a:Author),
 (l:Language)-[t:USED]->(w:Woka)-[u:INCLUDED]->(b:Bisac)
OPTIONAL MATCH (d:Description)-[v:HAS_DESCRIPTION]-(w:Woka)-[:AUTHORED]-(a:Author)
WHERE (a.author_name = 'Camus, Albert')
RETURN w.woka_id as woka_id, p.publisher_name as publisher_name, w.woka_title as woka_title, a.author_name as author_name, l.language_name as language_name, b.bisac_code as bisac_code, b.bisac_value as bisac_value, d.description as description
ORDER BY woka_id;

Don't know how to improve the query to get optional descriptions where exists and nulls when these don't exists for the original result set of 303 records?


Could you try this?

MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)<-[s:AUTHORED]-(a:Author), (l:Language)-[t:USED]->(w)-[u:INCLUDED]->(b:Bisac)
WHERE (a.author_name = 'Camus, Albert')
WITH p,r,w,s,a,l,t,u,b
OPTIONAL MATCH (d:Description)-[v:HAS_DESCRIPTION]-(w)
RETURN w.woka_id as woka_id, p.publisher_name as publisher_name, w.woka_title as woka_title, a.author_name as author_name, l.language_name as language_name, b.bisac_code as bisac_code, b.bisac_value as bisac_value, d.description as description
ORDER BY woka_id;