O'Reilly logo

Django By Example by Antonio Melé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving posts by similarity

Now that we have tagging for our blog posts, we can do many interesting things with them. Using tags, we can classify our blog posts very well. Posts about similar topics will have several tags in common. We are going to build a functionality to display similar posts by the number of tags they share. In this way, when a user reads a post, we can suggest them to read other related posts.

In order to retrieve similar posts for a specific post, we need to:

  • Retrieve all tags for the current post.
  • Get all posts that are tagged with any of those tags.
  • Exclude the current post from that list to avoid recommending the same post.
  • Order the results by the number of tags shared with the current post.
  • In case of two or more posts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required