Does this mean that you have at least ONE -[Seller]->[Buyer]-> pair? Did you try:
MATCH p = (rootTopic)-[:Seller|Buyer*]->(sellerCompanyTopic) WHERE ALL(idx in range(0,length(p)-2,2) WHERE type(rels(p)[idx]) = "Seller" AND type(rels(p)[idx+1]) = "Buyer") or MATCH p = (rootTopic)-[:Seller]->()-[:Buyer]->()-[:Seller|Buyer*0..]->(sellerCompanyTopic) WHERE ALL(idx in range(2,length(p)-2) WHERE type(rels(p)[idx]) = type(rels(p)[idx-2])) > Am 06.10.2015 um 11:34 schrieb Ryan Velasco <[email protected]>: > > Thanks for the reply. Actually that query results nearly correct with sql > server counterpart. But there is an issue with shortest path where in I > cannot dictate that it should be seller, buyer, seller, buyer.... > The new query right now which is nearly resulting to the same result as our > sql server view is: > > MATCH > (sellerCompanyTopic:Company)-[rel:Seller]->(sr:SalesRelation)-[rel2:Buyer]-(buyer:Company), > > sr<-[pa:PriceAgreement]-(contract:Contract) > WHERE ((contract.ContractEndDate >= 635796943890000000) AND > (contract.ContractStartDate <= 635796943890000000) > AND (pa.EndDate >= 635796951430000000) AND (pa.StartDate <= > 635796951430000000)) > MATCH (rootTopic:Company) WHERE rootTopic.ID = 172086 > OPTIONAL MATCH p = > allshortestPaths(rootTopic-[:Seller|Buyer*]-sellerCompanyTopic) > WITH rootTopic, sellerCompanyTopic, buyer, contract, > reduce( > index = 0, > rel IN relationships(p)| > case > when index % 2 = 0 AND type(rel) = 'Buyer' > then -1000 > when index % 2 = 1 AND type(rel) = 'Seller' > then -1000 > ELSE index + 1 > END > ) AS Related > WHERE rootTopic = sellerCompanyTopic OR rootTopic = buyer OR Related > 0 > RETURN distinct buyer.ID AS BuyerTopicID, contract.ID AS ContractTopicID, > case > when Related is null > then 1 > when Related < 0 > then 0 > when rootTopic = buyer > then 0 > ELSE Related > END AS Depth > ORDER BY BuyerTopicID, ContractTopicID > > The problem is the allshortestpaths because I cannot dictate that it should > be seller, buyer, seller, buyer.... > Which become a problem for this scenario : > > Company1 > | > | Sells to (via contract A) > | > Company2 > > > Company2 > | > | Sells to (via Contract B) > | > Company3 > > > Company3 > | > | Sells to (via Contract C) > | > Company4 > > > Company4 > | > | Sells to (via Contract D) > | > Company1 > > For Checking if Company 1 Seller Buyer Chain with Company 4, > the problem is that the shortest path is always Contract D and the correct > path should be A + B + C path. > > -- > 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] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- 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.
