Given the time range during the day (working hours), how could you create an index that would return an object based on the current time.

I made the mistake of assuming that a list property containing only open and closed clocks could run on the application engine. The following errors fail because the two inequality filters must match the same value in the list:

``````Select * FROM Business WHERE hours < now AND hours > now
```

```

Now I'm a bit invested and with no solution other than using a long list of times, sliced ββevery 30 minutes, which seems very inefficient:

``````[900, 930, 1000, 1030, 1100, 1130, 1200, 1230, 1300, 1330, 1400, 1430, ... ]
```

```

Does anyone know of a clever way of hashing open and close time or otherwise solve this problem?

+3

source to share

NEW ANSWER: I thought about it a bit, I think you actually have a solution in your original idea. For each business, there is a ListProperty in the store, which only stores the times when the business is open, as it currently does. Then calculate the current time and round it to the nearest half hour, so 12:50 β 1200, then run the query

``````now = 1200
Select * FROM Business WHERE now in hours
```

```

I'm not sure about the correct syntax for GQL queries, but there is definitely an "in" filter there.

OLD ANSWER (Don't read) : I'm doing something like this, I really have no solution other than "try something different".

First, you need to keep the opening and closing times. Either as two separate fields, or encode them into one field, like "09001700" for 9-5, or even "M09001700". Or hash two numbers, I don't think it makes a huge difference no matter how you do it.

Then the bad news. I'm not particularly good at number theory, but what we're trying to do here is to encode two linear sets of numbers (opening and closing times) in such a way that you can do a linear> or <comparison on the third number that represents "now" ... I don't think this is possible, you can only get a successful> or <comparison on one of two numbers - opening or closing time. Therefore, given that we can only do one inequality on one property, I do not think it is possible for a single query to isolate only open repositories.

I also don't think you need to make two requests, you only need to make one request, say opening hours, and then skip through them to see which ones are closed. If you

You don't necessarily need two large sets together. You can query all items where now is> opentime and manually filter the search results for items where now is <closetime. Sorting your query based on time should make filtering a little easier.

The solution I ended up going with, which might work for you, is to not query the store hours at all, but query what will return a more limited set of data, then filter the results returned based on the store hours. For example, if your users search by location, query your businesses based on location, and filter the resulting business by store time, then only those open to the user are displayed.

+2

source

One such action would be to set opentime and near time for each business and see if the time of day is in between.

However, with a large table, you may need to run two separate queries due to indexing. One request to see if the time is longer than opentime and the other to see if it is less than the time. This will be two indices.

Not a perfect solution, but it may be more effective than what you are trying to do.

0

source

All Articles