Search the nodes to find recipe they are connected to


(Drajkovic992) #1

Hello everyone. I am trying to construct a search query with Neo4j that will look for recipes with 2 levels of initial node, and then output them by number of time some relationship exist on the recipe node.

My query looks like this now

WHERE CONTAINS "pizza" OR n.content CONTAINS "pizza" OR n.title CONTAINS "pizza"
WITH r, count(a) as c
return r,c 
order by c desc

This will return recipes with most matches on top, but i am not satisfied with my results, for example pasta has more connections than 15 minutes pizza recipe. So technically when user type pizza first thing that shows up will be pasta. Is there an IF statement in CYPHER that i can use to check if name of recipe include search query and return that first?
I think this might be a trivial question, but i just started with GraphDB and everything is pretty new to me.
Thanks for help!

(Kevin Urban) #2

Hey, I think your issue might be resolved with a WITH statement or two, or a CASE statement, or maybe a weighted counting scheme...but hard to say. It would be helpful if you could provide the full query (seems you only provided a partial query) and an example data set.

(Drajkovic992) #3

My main goal is to find the recipe with 2 lvls deep node, but also sort with how many connections there are because more connections better chances that we found right thing. This is query is doing something for me, but it's far from good i am sure.

(Andrew Bowman) #4

It sounds like what you want is a full text index with weights on matches, that way you can do an index lookup across nodes of multiple types and either apply filtering based on weight at that point, or perform a match and include both the weighting and the number of relationships in your final weight calculation.

With Neo4j 3.4 and below, we have explicit index procedures for creating lucene indexes, but these are very manual and difficult to use with few examples.

We have just released Neo4j 3.5, which includes more powerful and useful full text indexes, which may help you out quite a bit.

Note that we're having a few hiccups with refreshing our documentation for 3.5, so you may want to monitor our documentation page for when we get the 3.5 docs up which will contain more info about full text index usage.

(Andrew Bowman) #5

Neo4j 3.5 is now available, and documentation has been updated. Here's the link to using full text indexes, which should be able to address your needs.