How does topic or tag suggestion algorithms work? I know it's a keyword based search. But sites like Quora have some good suggesting algorithms where the algorithm understands the intent of question asked rather than just the keywords meanings. 

For instance, for a question involving "O(n^2)" it adds 'Algorithms' and 'Computer Science' as topics and for a question involving "limit on friends in Facebook" it adds 'Facebook friends' as a topic. So it's more of a semantic search. 

Google search also works on the same principles of semantic search. So how exactly does tag suggestion algorithm work?
Read about topic modeling in natural language processing.  There are many techniques; e.g., LDA is one simple standard approach.