Changed getResourceIds method and implemented new method buildQuery.