[Solved] How to create an effectiveRange index?

I maintain a web site with events. I query the catalog using today/now in my query in order to find current and future events; it's working fine for events that are lasting one day (or less), but not for events starting on a date and ending on a later date. I'd like to query the catalog for a date range, but its effectiveRange index in empty, probably because it's optional.

How to generate a effectiveRange index to search for events with a duration of one or more days?

The effectiveRange index is calculated with the effective and expires dates of an object.

Using the range index shows only items which are inside this range, so even if you create your own dateRange index using start and end as parameter you would not get Events starting in the future. I think this query would fit your needs:

context.portal_catalog(
    end={
        "query": datetime.now(),
        "range": "min",
    })

So you get all items with end date larger than now.

Sidenote: If you mark open_end in an Event, the end date is autmatically set to the latest time of the same day.

Hi @petschki , you are correct; the effectiveRange index would be useless.

Because I provide the search with a date range, my final solution is:

        query['end'] = {
            'query': (start_date, end_date),
            'range': 'min:max'
        }

Thanks!

Edit: Nope! It's not yet working as expected...
A possible solution would be to use: GitHub - collective/Products.DateRangeInRangeIndex: Zope Index to query a date range on two target date indexes (start, end)
(I will try and report)

When you provide a daterange as search I suggest this one:

query["start"] = {
    "query": end_date,
    "range": "max",
}
query["end"] = {
    "query": start_date,
    "range": "min",
}
1 Like

Additional, if you need to check a query date range against a stored date range efficiently, there is an add-on Products.DateRangeInRangeIndex · PyPI