1
votes

I have items graph db. each item is connected to multiple properties, which can be shared by multiple items. I add a search node which is defined by few properties.

So I have (search_node) connected to multiple (properties_nodes) connected to multiple (items_nodes)

Now I would like to get a list of items who answer this search by {x} properties or more. Ordered by number of matching properties.

start se=node:node_auto_index(name = {name}), pr = node:node_auto_index(type="item_property")
MATCH p=(se) -[rt:SEARCH]- > (pr)<-[r]-(item)
WHERE Has(item.type) and (item.type = "item")
WITH item, collect(distinct pr.name) as rs
where length(rs) > {x}
RETURN item.name as item_name, length(rs) as matching_properties
ORDER BY  matching_properties desc 

The performance issue for me, is that it will search for all matching items, even those who match for only one property, and then remove all the items who are matching less than {x}. If {x} is higher than 1, it's a big waste.

How can I "MATCH" only by {x} matching properties?

Created a matching sample : http://console.neo4j.org/?id=adrgsh

(neo4j version 1.9.2)

1

1 Answers

3
votes

IMHO to be able to match only items with > x properties, you still need to find all those items that have properties in common with the search node. Post that, you can filter out the matches with < x properties in common. What kind of numbers are you getting? In your worst case, how many items were matched and how many were discarded?

You can simplify your query (matched results on the console but it could be missing some details that are not specified in this question)

START se=node(11) 
MATCH (se)-[:SEARCH]- >(pr)<-[:HAS]-(item) 
WHERE HAS (item.type) AND (item.type = "item") 
WITH count(pr) AS matching_properties, item 
WHERE matching_properties>1 
RETURN item.name AS item_name, matching_properties 
ORDER BY matching_properties DESC