Weights on node lables

I have a requirement where I want to add weights to the node labels and return the queried list based on these weights. Suppose a person node has two labels company and title and a search query matches both these fields, since the company label has more weight assigned, it should be returned on top of the list. I have created FULLTEXT index on node labels for search already.

Is it possible to do something like this with neo4j ?

You could derive a ‘rank’ value based on the labels present and use the rank value in an ‘order by’ clause to sort by rank. Something like the following as an example.

match(n)
where n:Label1 or n:Label2
with n, 
case when n:Label1 then 0.75 else 0 end as label1_weight, 
case when n:Label2 then 0.55 else 0 end as label2_weight
with n, label1_weight+label2_weight as rank
return n, rank
order by rank desc

3 Likes