Prakhar Pratyush

Tag merging in Ques10

May 22, 2021

This blog is about a very exciting functionality upon which I worked during my internship at Ques10.

Will take you through the task assigned, approach, and the final solution which I finally built. Just to make things a little interesting, you will get to know about the design pattern of a very interesting feature of Stack Overflow named Merge Tags.

Ques10 is a website just like Stack Overflow, where students from different domains ask questions and resolve queries of others.

Task

Whenever a user asks a question, he/she has to add at least one tag to that question ‘stackoverflow works in the same manner’.

Now suppose three different users asked a question related to Machine Learning :

  • user1 added a tag ML
  • user2 added a tag M learning
  • user3 added a tag Machine Learning

Ideally, all the tags refer to the same thing, so there should be just one tag. e.g.

  • Parent Tag : Machine Learning
  • Children Tags: ML , M learning

So the task was to build a Merge Tag Tool in Django Admin, from where moderators can merge these similar tags manually and at the same time all the CRUD functionality related to tags should be handeled accordingly.

Approach

The loophole I found in the task assigned to me was that, if we built a tool from where manual merging will take place then it will be a never ending process because,

Suppose we merged children tags to parent today… Tomorrow users will again create that and this will result in never ending process.

I did some research regarding this, how others are managing this!

Obviously the best player in this field is Stack Overflow.

They maintain a Parent-Children relation inbetween tags, once you merge children tags : ml, M learning with the parent Machine Learning now system will work like this :

  • Step 1 : new user puts a tag ml during question creation
  • Step 2 : System checks if that tag already exists in the children field or Parent field of Tag table.
  • Step 3 : If it exists in children field, replace that tag with parent of that children i.e. Machine Learning
  • Step 4 : If it exists in Parent field, do nothing.
  • Step 5 : If it doesn’t exists in either , just create the tag as new tag.

Solution

I added two fields named parent and children in the Tag Table and follwed the same algorithm discussed above.

Of course I had to work a lot to make sure, all the CRUD functionality related to Tag works in Sync with this new feature, also learnt a lot regarding Django Admin Panel Customization

The Biggest plus point of this was now :

Once ml is merged with Machine Learning, now in future system will automatically merge 'ml' tag with Machine Learning whenever it is created during question creation

It is now, not an never ending process.

You can visit this Stack Exchange blog to read more about this functionality.

Thanks !

© 2025 Prakhar Pratyush