Consider number of occurrences

I want to consider the queries number of occurrences in an attribute.
More specifically:
There is a category attribute which can look like this: “Milk and eggs -> Milk products -> Milk”
Searching for “Milk” returns all products in the first level category “Milk and eggs”. I want products whose category contains more occurrences of milk to be further at the top, so the more specific categories are weighed higher. As it is now, a product in the category “Milk and eggs -> eggs” is ranked the same as a product in “Milk and eggs -> Milk products”.

I also wondered why there is no “reverse order” option, so matches further from the beginning of an attribute are ranked higher. This would solve my problem too.