Refactor search handler in the core and add search handler for tags