Search code examples
neo4jnosql

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?


Solution

  • 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