Skip to content

Commit

Permalink
Merge pull request #33977 from dimagi/ad/add-match-all-csql
Browse files Browse the repository at this point in the history
Add match_all query function
  • Loading branch information
AddisonDunn committed Jan 17, 2024
2 parents 268ece9 + e5f7e89 commit b6984b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
19 changes: 19 additions & 0 deletions corehq/apps/case_search/tests/test_case_search_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,22 @@ def test_index_case_search(self):
'indices.host': ['c1'],
}).get_ids()
self.assertItemsEqual(actual, ['c4'])

def test_match_all(self):
self._create_case_search_config()
cases = [
{'_id': 'c1', 'case_type': 'song', 'description': 'New York'},
{'_id': 'c2', 'case_type': 'song', 'description': 'Manchester'},
{'_id': 'c3', 'case_type': 'song', 'description': 'Manchester Boston'},
]
self._assert_query_runs_correctly(
self.domain,
cases,
get_case_search_query(
self.domain,
['song'],
{'_xpath_query': "match-all()"},
),
None,
['c1', 'c2', 'c3']
)
8 changes: 8 additions & 0 deletions corehq/apps/case_search/tests/test_filter_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ def _test_xpath_query(self, query_string, expected_filter, context=None):
built_filter = build_filter_from_ast(parsed, context)
self.checkQuery(built_filter, expected_filter, is_raw_query=True)

def test_match_all(self):
parsed = parse_xpath("match-all()")
expected_filter = {
"match_all": {}
}
built_filter = build_filter_from_ast(parsed, SearchFilterContext("domain"))
self.checkQuery(built_filter, expected_filter, is_raw_query=True)


@es_test(requires=[case_search_adapter], setup_class=True)
class TestFilterDslLookups(ElasticTestMixin, TestCase):
Expand Down
4 changes: 3 additions & 1 deletion corehq/apps/case_search/xpath_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
selected_any,
within_distance,
phonetic_match,
starts_with
starts_with,
match_all
)
from .subcase_functions import subcase
from .ancestor_functions import ancestor_exists
Expand All @@ -32,4 +33,5 @@
'phonetic-match': phonetic_match,
'starts-with': starts_with,
'ancestor-exists': ancestor_exists,
'match-all': match_all
}
9 changes: 9 additions & 0 deletions corehq/apps/case_search/xpath_functions/query_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,12 @@ def _property_name_to_string(value, node):
_(f"The first argument to '{node.name}' must be a valid case property name"),
serialize(node)
)


def match_all(node, context):
if len(node.args):
raise XPathFunctionException(
_("'match-all()' does not take any arguments"),
serialize(node)
)
return filters.match_all()

0 comments on commit b6984b8

Please sign in to comment.