Fix for the search query in the term table
Modularizing the term query a little bit more