BadFilterError: invalid filter: Only one property

2019-02-18 15:54发布

I am trying to apply filter on two diffrent properties but it GAE isn't allow me to do this what will be the solution then, there it is the code snipt:

if searchParentX :
    que.filter("parentX >=", searchParentX).filter("parentX <=", unicode(searchParentX) + u"\ufffd") 
    que.order('parentX')   

if searchParentY :
    que.filter("parentY >=", searchParentY).filter("parentY <=", unicode(searchParentY) + u"\ufffd") 

2条回答
孤傲高冷的网名
2楼-- · 2019-02-18 16:02

The solution would be to do an in memory filtering:

  1. You can run two queries (filtering on one property each) and do an intersection on the results (depending on the size of the data, you may need to limit your results for one query but not the other so it can fit in memory)
  2. Run one query and filter out the other property in memory (in this case it would be beneficial if you know which property would return a more filtered list)

Alternatively, if your data is structured in such a way that you can break the data into sets you can perform equality filters on that set and finish filtering in memory. For example, if you are searching on strings but you know the strings to be a fixed length (say 6 characters), you can create a "lookup" field with the begging 3/4 characters. Then when you need to search on this field, you do so by matching on the first few characters, and finish the search in memory. Another example: when searching for integer ranges, if you can define common grouping of ranges (say decades for a year, or price ranges), then you can define a "range" field to do equality searches on and continue filtering in memory

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-18 16:09

Inequality filters are limited to at most one property, i think this restriction is because the data in bigtable is stored in lexical sorted form so at one time only one search can be perform

https://developers.google.com/appengine/docs/python/datastore/queries#Restrictions_on_Queries

查看更多
登录 后发表回答