def _apply_filter(self, search_es, criteria): if criteria.key == CASE_SEARCH_XPATH_QUERY_KEY: if not criteria.is_empty: if criteria.has_multiple_terms: for value in criteria.value: search_es = search_es.filter( build_filter_from_xpath(self.query_domains, value)) return search_es else: return search_es.filter( build_filter_from_xpath(self.query_domains, criteria.value)) elif criteria.key == 'owner_id': if not criteria.is_empty: return search_es.filter(case_search.owner(criteria.value)) elif criteria.key == CASE_SEARCH_BLACKLISTED_OWNER_ID_KEY: if not criteria.is_empty: return search_es.filter( case_search.blacklist_owner_id(criteria.value_as_list)) elif criteria.key == COMMCARE_PROJECT: if not criteria.is_empty: return search_es.filter(filters.domain(criteria.value)) elif criteria.key not in UNSEARCHABLE_KEYS: return search_es.add_query(self._get_case_property_query(criteria), queries.MUST) return search_es
def test_filtered_forms(self): json_output = { "query": { "filtered": { "filter": { "and": [ {"term": {"domain.exact": "zombocom"}}, {"term": {"xmlns.exact": "banana"}}, {"not": {"missing": { "field": "domain"}}}, {"term": {"doc_type": "xforminstance"}}, {"not": {"missing": {"field": "xmlns"}}}, {"not": {"missing": {"field": "form.meta.userID"}}}, ] }, "query": {"match_all": {}} } }, "size": SIZE_LIMIT } query = forms.FormES()\ .filter(filters.domain("zombocom"))\ .xmlns('banana') self.checkQuery(query, json_output)
def test_filtered_forms(self): json_output = { "query": { "filtered": { "filter": { "and": [ {"term": {"domain.exact": "zombocom"}}, {"term": {"xmlns.exact": "banana"}}, {"not": {"missing": { "field": "domain"}}}, {"term": {"doc_type": "xforminstance"}}, {"not": {"missing": {"field": "xmlns"}}}, {"not": {"missing": {"field": "form.meta.userID"}}}, ] }, "query": {"match_all": {}} } }, "size": SIZE_LIMIT } query = forms.FormES()\ .filter(filters.domain("zombocom"))\ .xmlns('banana') self.checkQuery(query, json_output)
def test_filtered_forms(self): json_output = { "query": { "filtered": { "filter": { "and": [ {"term": {"domain.exact": "zombocom"}}, {"term": {"xmlns.exact": "banana"}}, {"not": {"missing": { "field": "domain"}}}, {"term": {"doc_type": "xforminstance"}}, {"not": {"missing": {"field": "xmlns"}}}, {"not": {"missing": {"field": "form.meta.userID"}}}, ] }, "query": {"match_all": {}} } }, "size": SIZE_LIMIT } query = forms.FormES()\ .filter(filters.domain("zombocom"))\ .xmlns('banana') raw_query = query.raw_query self.assertItemsEqual( raw_query['query']['filtered']['filter'].pop('and'), json_output['query']['filtered']['filter'].pop('and') ) self.checkQuery(raw_query, json_output, is_raw_query=True)
def test_filtered_forms(self): json_output = { "query": { "bool": { "filter": [ { "term": { "domain.exact": "zombocom" } }, { "term": { "xmlns.exact": "banana" } }, { "term": { "doc_type": "xforminstance" } }, { "exists": { "field": "xmlns" } }, { "exists": { "field": "form.meta.userID" } }, { "exists": { "field": "domain" } }, ], "must": { "match_all": {} } } }, "size": SIZE_LIMIT } query = forms.FormES()\ .filter(filters.domain("zombocom"))\ .xmlns('banana') raw_query = query.raw_query self.checkQuery(raw_query, json_output, is_raw_query=True)