I face a rather common problem of displaying a list of nodes similar to current one. Similar node is defined as one having at least one taxonomy term that current node has. There are few solutions available as modules, however most modules I've found are in beta stage for Drupal 7.

I've also found a couple of solutions based on Views and contextual filters (such as http://scito.ch/content/show-related-nodes-block-based-taxonomy-terms-views-3-and-drupal-7) or relations. I quite like this way as it saves me installing extra modules and with Views being actively developed and supported I'd prefer to use them rather than any custom solution. The problem I can't get around is how to sort "similar nodes" by the number of terms they share. For example, if I have "IPhone 4S" Node with Terms "Gadget", "Apple", and "Phone", I want similar nodes in the following order:

  1. IPhone 3 (Apple, Gadget, Phone)
  2. IPad (Apple, Gadget, Tablet)
  3. Mac (Apple, Computer)
  4. Bramley (Apple, Fruit, Tree)

How can I sort nodes in this view by the number of terms they share?

  • Since you still haven't had many answers, I just wanted to point out that I'm fairly certain that with Views and it's aggregation settings, you can achieve this. It's something I've been meaning to test further myself, but never got around to it. This is essentially what Similar By Terms but far less rigid.
    – Letharion
    Commented Apr 27, 2012 at 6:36
  • 1
    For those upvoting and favoriting, I've got the answer here: stackoverflow.com/questions/10454507/…
    – docfish-ru
    Commented Jul 8, 2012 at 6:32

2 Answers 2


For those upvoting and favoriting, I've got the answer here: https://stackoverflow.com/questions/10454507/creating-list-of-similar-nodes-in-drupal-7-views-3

It boils down to:

  1. Create a block view
  2. Add Contextual filter -> Content: Nid -> Provide default value -> Content ID from URL
  3. Add Relationship -> Content: Taxonomy terms on node -> specify the appropriate vocabulary
  4. Add Relationship -> Taxonomy term: Content using vocabulary as specified above -> Check off Require this relationship
  5. Turn on Views aggregation
  6. Assuming you are listing title only, edit the title field to use the Relationship you set up in #4 above.
  7. Add new sort criteria of Content: Nid. In aggregation settings, select Count. Use relationship from #4 and sort descending
  8. Add Contextual filter -> Content: Nid -> Use relationship from #4 -> Provide default value - Content ID from URL -> Scroll down and expand "More" then check "Exclude" to remove current node from the view.

To get the results easily, try the Similar By Terms module.

  • I'm a bit reluctant to use beta version of any module. Specifically after installing Similar By Terms and enabling its block I get "Warning: Invalid argument supplied for foreach() в функции similarterms_taxonomy_node_get_terms()" (though it displays something credible in the block).
    – docfish-ru
    Commented May 4, 2012 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.