Extract filter_by_selection function.