简体   繁体   中英

How to find nodes with most similar indirect connections in Neo4j

I am trying to make a headphone recommendation tool where it shows you the most similar headphones to a specific set.

I have :Headphone and a lot of different indirect connections, for example :Brand or :Price_Point .

For example, I'm looking for similar headphones to :Headphone called "HD600" and it's made by the brand Sennheiser so I want to get the headphones that have the most similar connections, for example being also made by Sennheiser, in the same Price range, in the same Sound Signature, etc...

If I for example run

MATCH (q:Headphone {name: 'HD600'})-[ind_connector1]-(ind_connection)-[ind_connector_2]-(other_headphone: Headphone)
RETURN q, ind_connection, other_headphone LIMIT 5

it will just return me five headphones that are also over-ear but not similar in any other way. Is there any way I can get the Nodes with the most similar connections?

You can try something like this (counting the distinct ind_connections) between two headphones.

MATCH (q:Headphone {name: 'HD600'})-[ind_connector1]-(ic:ind_connection)-[ind_connector_2]-(other_headphone: Headphone)

RETURN q, other_headphone, COUNT( DISTINCT ic) AS ics
ORDER BY ics DESC
LIMIT 5

This is how to get other headphones with the same brand and price range.

Start with your headphone with name: 'HD600' and related headphone (h2) of the same brand Sennheiser. Then look for the Price (p) and find related headphones with the same price (p)

//find headphones (h2) with the same brand 
MATCH (h1:Headphone {name: 'HD600'}) -- (b:Brand) -- (h2:Headphone) , (h1) -- (p:Price_Point)
//find related headphones (h2) with the same price
MATCH (h2) -- (p)
RETURN h1, h2, b, p LIMIT 5

在此处输入图像描述

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