Finish the implementation of result filtering at DB level