Extracted Library.filter_search inner functions to a new global function for simplification