Implementing “Starts with” and “Ends with” queries with Google App Engine

余生长醉 提交于 2019-12-09 00:03:25

问题


Am wondering if anyone can provide some guidance on how I might implement a starts with or ends with query against a Datastore model using Python?

In pseudo code, it would work something like...

Query for all entities A where property P starts with X

or

Query for all entities B where property P ends with X

Thanks, Matt


回答1:


You can do a 'starts with' query by using inequality filters:

MyModel.all().filter('prop >=', prefix).filter('prop <', prefix + u'\ufffd')

Doing an 'ends with' query would require storing the reverse of the string, then applying the same tactic as above.




回答2:


Seems you can't do it for the general case, but can do it for prefix searches (starts with):

Wildcard search on Appengine in python



来源:https://stackoverflow.com/questions/1554600/implementing-starts-with-and-ends-with-queries-with-google-app-engine

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