refactored the search function for both tags and posts