Amazon Cloud Search - get places by time and date

547 Views Asked by At

I am using Amazon CloudSearch to store a large set of places. Each place has a opening time and a closing time, for each day of the week.

I need to retrieve places by current time. How do you suggest to model the index? I am thinking to solve the problem by creating 7 text indexes in which I specify, for each day of the week, the valid hours.

For example, if a place is opened from 9 am to 13 am, in the index "monday" I will write the string "9-10-11-12". Then, filtering by bq=monday:'10' or bq=monday:'16' I will have only the places that at the specified time are opened.

Any other idea? My solution seems working but would suggest me another approach?

1

There are 1 best solutions below

0
On

First, I wouldn't use multiple indexes.

You could use your approach, but just make the time in hours from the start of the week. So, Monday would be 0-23, Tuesday 24-47, etc. Or you could just have 7 fields, "monday_hours", "tuesday_hours", …

You could also use uints, instead of strings. Not better, but different, might be worth benchmarking.

With uints you can use range queries. If the document contained the fields "open" and "close" and you want to know if it's open between 10 and 12.

&bq=(and open:..12 close:10..)

One issue remaining is that CloudSearch's range searches are inclusive of endpoints. So I think this will show a false positive if the store opens at twelve. Technically, the ranges overlap, but not usefully. To fix that, I'd do two things. First, I wouldn't go by hours, I'd use minute-of-the-day as the value in the field (0 to 1439). Then add one to the starting range, and subtract one from the end.

Using uints will perform differently from using text fields. I'd definitely benchmark them to see which one works better for you.