Neo4j - don't know how to improve cypher query -
i have query returning fast, 0.5 seconds , returning 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) (a.author_name = 'camus, albert') return w.woka_id woka_id, p.publisher_name publisher_name, w.woka_title woka_title, a.author_name author_name, l.language_name language_name, b.bisac_code bisac_code, b.bisac_value bisac_value order woka_id;
and want add more info, description example. have description nodes created , relationships created, exists, between language , description , description , book (woka). query below returns descriptions null, 60 records instead of 303. because not books have description. execution time 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) (a.author_name = 'camus, albert') return w.woka_id woka_id, p.publisher_name publisher_name, w.woka_title woka_title, a.author_name author_name, l.language_name language_name, b.bisac_code bisac_code, b.bisac_value bisac_value, d.description description order woka_id;
however know of records left out result set, difference between 50 , 303 have description. build query using optional, 1 (shown below) never returns, runs 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) (a.author_name = 'camus, albert') return w.woka_id woka_id, p.publisher_name publisher_name, w.woka_title woka_title, a.author_name author_name, l.language_name language_name, b.bisac_code bisac_code, b.bisac_value bisac_value, d.description description order woka_id;
don't know how improve query optional descriptions exists , nulls when these don't exists original result set of 303 records?
could try this?
match (p:publisher)-[r:published]->(w:woka)<-[s:authored]-(a:author), (l:language)-[t:used]->(w)-[u:included]->(b:bisac) (a.author_name = 'camus, albert') p,r,w,s,a,l,t,u,b optional match (d:description)-[v:has_description]-(w) return w.woka_id woka_id, p.publisher_name publisher_name, w.woka_title woka_title, a.author_name author_name, l.language_name language_name, b.bisac_code bisac_code, b.bisac_value bisac_value, d.description description order woka_id;
Comments
Post a Comment