-
Notifications
You must be signed in to change notification settings - Fork 19
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
Extending temporal search #182
base: main
Are you sure you want to change the base?
Changes from 8 commits
2f8d666
7b33232
0a6616e
53d44ce
18d4be1
7eddfee
65ebbea
b514f19
5143f00
03c9701
7595509
8ed0928
0a6b9f1
5212768
0c1e08f
a2ec61e
c69c9e5
705bcb1
d15173e
4f31ac7
29ea9ba
44fd039
ea7646c
d003db1
0d89769
17818d3
fb41c03
8738bdc
4cf5f47
c99fda5
b95291e
14b5097
2c8ae68
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 |
---|---|---|
|
@@ -378,8 +378,8 @@ def apply_collections_filter(search: Search, collection_ids: List[str]): | |
return search.filter("terms", collection=collection_ids) | ||
|
||
@staticmethod | ||
def apply_datetime_filter(search: Search, datetime_search): | ||
"""Apply a filter to search based on datetime field. | ||
def apply_datetime_filter(search: Search, datetime_search: dict): | ||
"""Apply a filter to search on datetime, start_datetime, and end_datetime fields. | ||
|
||
Args: | ||
search (Search): The search object to filter. | ||
|
@@ -388,17 +388,101 @@ def apply_datetime_filter(search: Search, datetime_search): | |
Returns: | ||
Search: The filtered search object. | ||
""" | ||
should = [] | ||
|
||
if "eq" in datetime_search: | ||
search = search.filter( | ||
"term", **{"properties__datetime": datetime_search["eq"]} | ||
should.extend( | ||
[ | ||
Q( | ||
"bool", | ||
filter=[ | ||
Q( | ||
"term", | ||
properties__datetime=datetime_search["eq"], | ||
), | ||
], | ||
), | ||
Q( | ||
"bool", | ||
filter=[ | ||
Q( | ||
"range", | ||
properties__start_datetime={ | ||
"lte": datetime_search["eq"], | ||
}, | ||
), | ||
Q( | ||
"range", | ||
properties__end_datetime={ | ||
"gte": datetime_search["eq"], | ||
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. Should this be 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. Similarly this is searching for any items with a |
||
}, | ||
), | ||
], | ||
), | ||
] | ||
) | ||
|
||
else: | ||
search = search.filter( | ||
"range", properties__datetime={"lte": datetime_search["lte"]} | ||
) | ||
search = search.filter( | ||
"range", properties__datetime={"gte": datetime_search["gte"]} | ||
should.extend( | ||
[ | ||
Q( | ||
"bool", | ||
filter=[ | ||
Q( | ||
"range", | ||
properties__datetime={ | ||
"gte": datetime_search["gte"], | ||
"lte": datetime_search["lte"], | ||
}, | ||
), | ||
], | ||
), | ||
Q( | ||
"bool", | ||
filter=[ | ||
Q( | ||
"range", | ||
properties__start_datetime={ | ||
"gte": datetime_search["gte"], | ||
"lte": datetime_search["lte"], | ||
}, | ||
), | ||
], | ||
), | ||
Q( | ||
"bool", | ||
filter=[ | ||
Q( | ||
"range", | ||
properties__end_datetime={ | ||
"gte": datetime_search["gte"], | ||
"lte": datetime_search["lte"], | ||
}, | ||
), | ||
], | ||
), | ||
Q( | ||
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. Could you explain this last query? Do both 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. This part concerns date range searches. It returns any items who's
I think this captures all cases. Apologies if any of this is unclear. |
||
"bool", | ||
filter=[ | ||
Q( | ||
"range", | ||
properties__start_datetime={ | ||
"lte": datetime_search["gte"] | ||
}, | ||
), | ||
Q( | ||
"range", | ||
properties__end_datetime={ | ||
"gte": datetime_search["lte"] | ||
}, | ||
), | ||
], | ||
), | ||
] | ||
) | ||
|
||
search = search.query(Q("bool", filter=[Q("bool", should=should)])) | ||
|
||
return search | ||
|
||
@staticmethod | ||
|
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.
Should this be
"gte": datetime_search["eq"],
to find the dates larger than thestart_datetime
?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.
Yes and no, It's a bit counter intuitive. The check it's actually the opposite, so it's searching for any items with a
start_datetime
that's before or equal to (lte
) the givendatetime_search["eq"]
.