[3.8] Refactor search engine