-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fuzzy-date function to case search #35065
Changes from all commits
2814c17
fe75789
acc4f66
ec9d241
023eb53
1c2e1c7
75e7234
e28bbfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,7 +233,7 @@ def multiplex_to_adapter(domain): | |
return None | ||
|
||
|
||
def case_property_query(case_property_name, value, fuzzy=False, multivalue_mode=None): | ||
def case_property_query(case_property_name, value, fuzzy=False, multivalue_mode=None, boost_first=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @esoergel I am feeling a bit iffy about adding yet another flag here. I see two alternatives:
|
||
""" | ||
Search for all cases where case property with name `case_property_name`` has text value `value` | ||
""" | ||
|
@@ -254,6 +254,15 @@ def case_property_query(case_property_name, value, fuzzy=False, multivalue_mode= | |
queries.match(value, PROPERTY_VALUE, operator=multivalue_mode) | ||
), | ||
) | ||
if boost_first: | ||
return _base_property_query( | ||
case_property_name, | ||
filters.OR( | ||
filters.term(PROPERTY_VALUE, value), | ||
queries.match(value[0], PROPERTY_VALUE) | ||
) | ||
|
||
) | ||
if not fuzzy and multivalue_mode in ['or', 'and']: | ||
return case_property_text_query(case_property_name, value, operator=multivalue_mode) | ||
return exact_case_property_text_query(case_property_name, value) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,10 +391,11 @@ def _bootstrap_cases_in_es_for_domain(self, domain, input_cases): | |
|
||
def _assert_query_runs_correctly(self, domain, input_cases, query, xpath_query, output): | ||
self._bootstrap_cases_in_es_for_domain(domain, input_cases) | ||
self.assertItemsEqual( | ||
query.get_ids(), | ||
output | ||
) | ||
if query: | ||
self.assertItemsEqual( | ||
query.get_ids(), | ||
output | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think other tests put the xpath query as part of a call to |
||
if xpath_query: | ||
self.assertItemsEqual( | ||
CaseSearchES().xpath_query(self.domain, xpath_query).get_ids(), | ||
|
@@ -435,6 +436,20 @@ def test_fuzzy_case_property_query(self): | |
['c3'] | ||
) | ||
|
||
def test_fuzzy_date(self): | ||
self._assert_query_runs_correctly( | ||
self.domain, | ||
[ | ||
{'_id': 'c1', 'dob': date(2020, 3, 1)}, | ||
{'_id': 'c2', 'dob': date(2020, 1, 3)}, | ||
{'_id': 'c3', 'dob': date(2002, 3, 1)}, | ||
{'_id': 'c4', 'dob': date(2020, 3, 4)}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
], | ||
None, | ||
"fuzzy-date(dob, '2020-03-01')", | ||
['c1', 'c2', 'c3'] | ||
) | ||
|
||
def test_multiple_case_search_queries(self): | ||
query = (CaseSearchES().domain(self.domain) | ||
.case_property_query("foo", "redbeard") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Know you're still working on this. Have you thought about adding a test that validates the output of the query is as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AddisonDunn is there a test the run ES queries against test data already? I am having trouble finding any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests in
test_case_search_filters
test that a query in a case search function returns the cases expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AddisonDunn pushed the test