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

[亡魂溺海] 提交于 2019-12-01 06:47:21

问题


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") 

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/13391818/badfiltererror-invalid-filter-only-one-property-per-query-may-have-inequality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!