NoSQL选择覆盖给定timeRange的timeRanges

时间:2022-09-15 18:27:19

I am using Google App Engine's Datastore as my database. I have a bunch of users let's call them providers that have given what time ranges they are available for the week. Like 3-4 p.m. and 4:30-7:30 p.m. Then, another user comes along and says I want to see who is available from 5-6 p.m. on this day. How do I get the list of users that have said they are available from 5-6 p.m. What is the best way to model the data and get this result?

我使用Google App Engine的数据存储区作为我的数据库。我有一大堆用户让我们称之为提供商,这些提供商已经给出了本周可用的时间范围。比如下午3-4点下午4:30-7:30然后,另一位用户出现并说我希望从下午5-6点看谁有空。在这一天。我如何从下午5-6点获得表示可用的用户列表。对数据建模并获得此结果的最佳方法是什么?

2 个解决方案

#1


0  

It would be good to know what language do you use. I assume that you use Java and Objectify. Code below omits some details. Essentially you need to index fromDate and toDate and after to filter providers based on parameters got from user input.

知道你使用什么语言会很好。我假设您使用Java和Objectify。下面的代码省略了一些细节。基本上你需要索引fromDate和toDate以及之后根据从用户输入获得的参数过滤提供者。

public class Provider {

    ...
    @index Date availableFrom;
    @index Date availableTo; 
    ...

}

public class ProviderService {

    @ApiMethod(name = "getByRange")
    public List<Provider> getByRange( @Named("availableFrom") String   
                    availableFrom, @Named("availableTo") String availableTo{

        List<Provider> providers=   
            ofy().load().type(Provider.class).filter("availableFrom >=",  
              availableFrom).filter("availableTo <=", availableTo).list();
        return providers;
}

Objectify queries

客观化查询

Filter by date example

按日期过滤示例

Multiple filters example

多个过滤器示例

#2


0  

Tim Hoffman's comment is the correct answer. Use time increments and store variables for each increment. Turin is correct if there is only one time range that you are available, but with multiple time ranges the problem becomes very different.

蒂姆霍夫曼的评论是正确的答案。为每个增量使用时间增量和存储变量。如果只有一个时间范围可用,都灵是正确的,但是对于多个时间范围,问题会变得非常不同。

#1


0  

It would be good to know what language do you use. I assume that you use Java and Objectify. Code below omits some details. Essentially you need to index fromDate and toDate and after to filter providers based on parameters got from user input.

知道你使用什么语言会很好。我假设您使用Java和Objectify。下面的代码省略了一些细节。基本上你需要索引fromDate和toDate以及之后根据从用户输入获得的参数过滤提供者。

public class Provider {

    ...
    @index Date availableFrom;
    @index Date availableTo; 
    ...

}

public class ProviderService {

    @ApiMethod(name = "getByRange")
    public List<Provider> getByRange( @Named("availableFrom") String   
                    availableFrom, @Named("availableTo") String availableTo{

        List<Provider> providers=   
            ofy().load().type(Provider.class).filter("availableFrom >=",  
              availableFrom).filter("availableTo <=", availableTo).list();
        return providers;
}

Objectify queries

客观化查询

Filter by date example

按日期过滤示例

Multiple filters example

多个过滤器示例

#2


0  

Tim Hoffman's comment is the correct answer. Use time increments and store variables for each increment. Turin is correct if there is only one time range that you are available, but with multiple time ranges the problem becomes very different.

蒂姆霍夫曼的评论是正确的答案。为每个增量使用时间增量和存储变量。如果只有一个时间范围可用,都灵是正确的,但是对于多个时间范围,问题会变得非常不同。