rewrite index item query logic