简体   繁体   中英

neo4j query performance tuning with node(*)

I have added nodes with a "nodetype" property, and want to query just a certain type of node. For instance, I have a "venue" nodetype which is a list of venues around the world. Each venue has a :IN_REGION which links it to a city, and then there is a :IN_REGION all the way up to the country. So:

venue-[:IN_REGION]->city-[:IN_REGION]->province-[:IN_REGION]->country

I am implementing a fuzzy search on the venues, and need to search on any of the above and return a string with all of the above concatenated. I would like to do this on Neo4j instead of on the back-end server. What would b the ideal query to run on this? I have the following:

START venue=node(*)
WHERE venue.nodetype! ='venue'
WITH venue
MATCH p = address<-[:HAS_ADDRESS]-venue-[r1:IN_REGION]->city-[r2?:IN_REGION]->prov-[r3?:IN_REGION]->country
with venue.name+','+address.streetAddress+','+city.name+','+prov.name+','+country.name as toSearch
WHERE toSearch=~ ".*QUERY_STRING.*"
return toSearch
LIMIT 30

where QUERY_STRING is the fuzzy search string. I am mostly wondering about the node(*) and having the query at the end - is this going to comb through every single node? Also, some of the relationships are optional and return null - how do I handle that?

Any help is greatly appreciated!

You're basically telling it to scan the entire DB for venue nodes (a good optimization would be to have an index for nodetype or just venue nodes, and scan that), and then traversing all venue's addresses/cities/etc., and then comparing those addresses to the search string. Your limit isn't going to help your performance much, and it's going to stink unless you have a very small db. How many venues do you have? In any case, you might consider something like this:

start venue=node:venue_index('name:*QUERY_STRING*')
match address<-[:HAS_ADDRESS-venue-[:IN_REGION]->city-[?:IN_REGION]->prov-[?:IN_REGION]->country
return venue.name + ',' + address.streetAddress + ',' + city.name + ',' + coalesce(prov.name?, '') + ',' + coalesce(country.name?, '') as toSearch

start city=node:city_index('name:*QUERY_STRING*')
match address<-[:HAS_ADDRESS-venue-[:IN_REGION]->city-[?:IN_REGION]->prov-[?:IN_REGION]->country
return venue.name + ',' + address.streetAddress + ',' + city.name + ',' + coalesce(prov.name?, '') + ',' + coalesce(country.name?, '') as toSearch

And similar queries to address, prov, country. In 2.0 you can union these results together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM