无效过滤器:每个查询只有一个属性可能具有不等式过滤器(> =,< =,><) [英] invalid filter: Only one property per query may have inequality filters (>=, <=, >, <)

查看:136
本文介绍了无效过滤器:每个查询只有一个属性可能具有不等式过滤器(> =,< =,><)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些可在特定时间段预订的项目。例如。一个网球场。所以每个项目都有许多相关的可用性插槽,每个插槽都由begintime和endtime定义。 Begintime和Endtime被定义为日期时间对象,所以从09.00 - 11.30开始的可用性时间段被存储为例如。 2013-12-13 09.00(begintime)至2013-12-13 11.30(endtime)。



当预约请求进入时,我需要了解网球法院可用于所需的时间段。



因此,我试图根据开始时间和结束时间过滤可用性插槽,我的查询如下所示:

  desired_availability_start = datetime(2013,12,13,9,0,0)
desired_availability_end = datetime(2013, 13,10,0,0)
availability_slots = self.availability_slots.filter(begin< =,desired_availability_start).filter(end> =,desired_availability_end).fetch(limit = 10)

但我得到以下错误:

pre > 无效过滤器:每个查询只有一个属性可能具有不等式过滤器(> =,< =,> ;,<)

因为我试图过滤开始和结束属性。



基于输入和来自一些其他的帖子主题 AppEngine Datastore中的不等式过滤我目前的解决方案是先开始过滤:

  filtered_availability_slots = self。 availability_slots.filter(begin< =,desired_availability_start).fetch(limit = 10)

和然后在结尾过滤并将过滤的项目附加到列表中:

  final_availability_slots = [] 
for filtered in filtered_availability_slots:
if availability.end> = desired_availability_end:
final_avaialability_slotes.append(availability)

卜这是实现我想达到的最好方式吗?



我正在使用Google App Engine和Python



赞赏任何帮助



感谢
Thomas

解决方案

有点不清楚你问的是什么。目前还不清楚您是否理解这个问题:您试图使用两个不等式过滤器,而且这是不允许的。不能这样做。



您必须解决此数据存储限制。



最基本的选项是自己动手吧。使用一个过滤器,并手动过滤出结果。这可能有助于过滤 begin ,并在 end 上进行排序,但是您必须仔细阅读结果并选择你想要的实体。

  calitem = [x for self.appointments.filter(begin> = ,开始).filter(begin <=end)if x.end< = end] 



<在大多数情况下,您希望重新构建数据,以便不需要两个不等式过滤器。这可能或不可能。



我试图猜测你在做什么,但是如果你想看看有人在上午11点忙碌基于他们的日历,一种方法是:


  1. 将时间分解为时间段,而不是使用任意时间,即15分钟块。
  2. 将事件存储为它使用的时间块列表。

  3. 查询包含11am时间块的事件。
  4. li>


I have a number of items which are bookable in certain timeslots. Eg. a tennis court. So each item has got a number of associated availability slots each defined by begintime and endtime. Begintime and endtime are defined as datetime-objects so an availability slot from 09.00 - 11.30, is stored as eg. 2013-12-13 09.00 (begintime) to 2013-12-13 11.30 (endtime).

When a booking request comes in, I need to find out whether the tennis court is available for the desired timeslot.

So I am trying to filter availability slots based on start-time and end-time, and my query looks like this:

desired_availability_start = datetime(2013, 12, 13, 9,0,0)
desired_availability_end = datetime(2013, 12, 13, 10,0,0)
availability_slots = self.availability_slots.filter("begin <= ", desired_availability_start).filter("end >= ", desired_availability_end).fetch(limit=10)

but I get the following error

invalid filter: Only one property per query may have inequality filters (>=, <=, >, <)

Because I am trying to filter on both the begin- and end-property.

Based on the input and from some of the other posts on the topic Inequality Filter in AppEngine Datastore and BadFilterError: invalid filter: Only one property per query may have inequality filters (<=, >=, <, >) my current solution is to first filter on begin:

filtered_availability_slots = self.availability_slots.filter("begin <= ", desired_availability_start).fetch(limit=10)

and then filter on end and append the filtered items to a list:

final_availability_slots = []              
  for availability in filtered_availability_slots:         
      if availability.end >= desired_availability_end:  
        final_avaialability_slotes.append(availability)   

But is this the best way of achieving what I want to achieve?

I am using Google App Engine and Python

Any help is appreciated

thanks Thomas

解决方案

It's a bit unclear what you're asking. It's not clear whether you understand the problem: You're trying to use two inequality filters, and it's simply not allowed. Can't do it.

You must work around this datastore limitation.

The most basic option is to brute force it yourself. Use one filter, and manually filter out the results yourself. It may help to filter on begin, and sort on end, but you'll have to go through the results and pick the actual entities you want.

calitem = [x for x in self.appointments.filter("begin >= ", start).filter("begin <= " end) if x.end <= end]

In most cases, you'd want to restructure your data so that you don't need two inequality filters. This may or may not be possible.

I'm trying to guess at what you're doing, but if you're trying to see if someone is busy at 11am based on their calendar, a way to do this is:

  1. Break the day down into time periods instead of using arbitrary time, ie 15min blocks.
  2. Store an event as a list of the time blocks that it uses.
  3. Query for events that contain the time block for 11am.

这篇关于无效过滤器:每个查询只有一个属性可能具有不等式过滤器(&gt; =,&lt; =,&gt;&lt;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆