How do I implement something similar to how StackOverflow returns definitions for selective keywords in their search results as pictured below:

I am going to assume that I parse the string from my search field for possible matches to any tags and then return the lone definition with the greatest number of references (followers, posts, etc.). This seems rather inefficient when you consider the possibility of many tags and multiple word tags. Is this (parsing each word of the string) the best way to achieve this solution?
Feel free to illustrated with example code.
It is not inefficient way to parse search string and look for tags in key-value database or Sphinx index.
Both of the solutions are good for your purpose.
If you will store tag keys in memory it will work extremely fast.
Sphinx, Redis, MongoDb, MySQL (with MEMORY engine) can do that.