refactored the search method for posts