简体   繁体   English

使用Google App Engine实现“Start with with”和“Ends with”查询

[英]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? 我想知道是否有人可以提供一些指导,说明如何使用Python实现对数据存储模型的查询的开头或结束?

In pseudo code, it would work something like... 在伪代码中,它会像...一样工作

Query for all entities A where property P starts with X 查询属性P以X开头的所有实体A.

or 要么

Query for all entities B where property P ends with X 查询属性P以X结尾的所有实体B.

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 在Python中的Appengine上的通配符搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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