Criteria Builder in Neo4j
Posted By : Jasgeet Singh | 30-Nov-2017
In my one of the project, I got the
MapqueryParameters = new HashMap(); String query = "MATCH (c:Client{citizenDead:false})-[r:GET_SERVICE_FROM]->(o:Organization) WHERE id(o)= {unitId} AND id(c) in {citizenIds} AND ( c.firstName=~{name} OR c.lastName=~{name} ) AND c.cprNumber STARTS WITH {cprNumber} with c,r\n"; queryParameters.put("unitId", organizationId); queryParameters.put("name", clientFilterDTO.getName()); queryParameters.put("cprNumber", clientFilterDTO.getCprNumber()); queryParameters.put("phoneNumber", clientFilterDTO.getPhoneNumber()); queryParameters.put("civilianStatus", clientFilterDTO.getClientStatus()); queryParameters.put("skip", Integer.valueOf(skip)); queryParameters.put("latLngs", clientFilterDTO.getLocalAreaTags()); query += "OPTIONAL MATCH (c)-[:HAS_HOME_ADDRESS]->(ca:ContactAddress) with ca,c,r\n"; if(StringUtils.isBlank(clientFilterDTO.getPhoneNumber())){ query += "OPTIONAL MATCH (c)-[:HAS_CONTACT_DETAIL]->(cd:ContactDetail) with cd,ca,c,r\n"; }else{ query += "MATCH (c)-[:HAS_CONTACT_DETAIL]->(cd:ContactDetail) WHERE cd.privatePhone STARTS WITH {phoneNumber} with cd,ca,c,r\n"; } if(clientFilterDTO.getClientStatus() == null){ query += "OPTIONAL MATCH (c)-[:CIVILIAN_STATUS]->(cs:CitizenStatus) with cs,cd,ca,c,r\n"; }else{ query += "MATCH (c)-[:CIVILIAN_STATUS]->(cs:CitizenStatus) WHERE id(cs) = {civilianStatus} with cs,cd,ca,c,r\n"; } if(clientFilterDTO.getLocalAreaTags().isEmpty()){ query += "OPTIONAL MATCH (c)-[:HAS_LOCAL_AREA_TAG]->(lat:LocalAreaTag) with lat,cs,cd,ca,c,r\n"; } else{ query += "MATCH (c)-[:HAS_LOCAL_AREA_TAG]->(lat:LocalAreaTag) WHERE id(lat) in {latLngs} with lat,cs,cd,ca,c,r\n"; } query += "return {name:c.firstName+\" \" +c.lastName,id:id(c), age:c.age, emailId:c.email, gender:c.gender, cprNumber:c.cprNumber , citizenDead:c.citizenDead, joiningDate:r.joinDate,city:ca.city,"; query += "address:ca.houseNumber+\" \" +ca.street1, phoneNumber:cd.privatePhone, workNumber:cd.workPhone, clientStatus:id(cs), lat:ca.latitude, lng:ca.longitude, "; query += "localAreaTag:CASE WHEN lat IS NOT NULL THEN {id:id(lat), name:lat.name} ELSE NULL END} as Client ORDER BY c.firstName ASC SKIP {skip} LIMIT 20 "; return StreamSupport.stream(Spliterators.spliteratorUnknownSize(session.query(Map.class , query, queryParameters).iterator(), Spliterator.ORDERED), false).collect(Collectors.
I am hoping here you
Optional keyword, so in this
I hope this blog
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Jasgeet Singh
Jasgeet is a Sr. Lead developer .He is an experienced Groovy and Grails and has worked on designing & developing B2B and B2C portals using Grails technologies.