Thanks Lalit for your quick answer !!! I will re design a bit the system, because the solution you gave me I am not sure it fits to another test that I have since the relation between Paintings is not transitive. Since Painting_1 can be related to Painting_2 and to Painting_3 but this two last may not be related. And in this case I don't know how to implement the solution you give. About the second part of the solution I didn't see any particular change of performance.
Thanks again! El viernes, 1 de febrero de 2019, 7:38:43 (UTC+1), Lalit Singh escribió: > > I would recommend changing your Schema to something like: > [image: image.png] > > Because it will reduce *number of relationships *between Piece nodes from > *n^2 > to n*. And your query can then be something like: > > MATCH > (Paiting_1:Piece)-[:IN_HALL]->(Common_hall:Hall)<-[:IN_HALL]-(Paiting_2:Piece) > MATCH (Red_1:Color) > MATCH (Blue_1:Color) > WHERE Red_1.name CONTAINS 'Cherry' > AND Blue_1.name CONTAINS 'Sea' > AND NOT Paiting_1.name CONTAINS Paiting_2.name > AND (Red_1)-[:IS_IN]->(Paiting_1) > AND (Blue_1)-[:IS_IN]->(Paiting_2) > RETURN Paiting_1.name, > Paiting_2.name > > *Please share if there is a decrease in time by doing above and also after > try changing the order of conditions like:* > > MATCH (Paiting_1:Piece) > MATCH (Red_1:Color) > MATCH (Paiting_2:Piece) > MATCH (Blue_1:Color) > WHERE Red_1.name CONTAINS 'Cherry' > AND Blue_1.name CONTAINS 'Sea' > AND NOT Paiting_1.name CONTAINS Paiting_2.name > AND (Paiting_1)-[:IN_SAME_HALL]->(Paiting_2) > AND (Red_1)-[:IS_IN]->(Paiting_1) > AND (Blue_1)-[:IS_IN]->(Paiting_2) > RETURN Paiting_1.name, > Paiting_2.name > > > *Thanks & Regards* > *Lalit Kumar Singh | Software Developer* > > > On Thu, Jan 31, 2019 at 5:39 AM Ismael Rodríguez Brena < > ismarod...@gmail.com <javascript:>> wrote: > >> Hi everybody, >> >> I am complete beginner with Neo4j and I am trying to do an script which >> find patterns (particular subgraphs) in the Database. >> My query looks something like this: >> >> MATCH (Paiting_1:Piece) >> MATCH (Red_1:Color) >> MATCH (Paiting_2:Piece) >> MATCH (Blue_1:Color) >> WHERE Red_1.name CONTAINS 'Cherry' >> AND Blue_1.name CONTAINS 'Sea' >> AND NOT Paiting_1.name CONTAINS Paiting_2.name >> AND (Red_1)-[:IS_IN]->(Paiting_1) >> AND (Blue_1)-[:IS_IN]->(Paiting_2) >> AND (Paiting_1)-[:IN_SAME_HALL]->(Paiting_2) >> RETURN Paiting_1.name, >> Paiting_2.name >> >> This query gets me the expected result, but as soon the size of the >> subgraphs I am looking grows, the times need to answer the query increases >> exponentially. >> Probably there is a more fancy and efficient way to do it, but I haven't >> found it yet. >> >> Best, >> Ismael >> >> -- >> 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 neo4j+un...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > IMPORTANT: > NEVER share your IndiaMART OTP/ Password with anyone. > -- 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 neo4j+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.