简体   繁体   中英

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM