在蟒蛇中的Appengine上的通配符搜索 [英] Wildcard search on Appengine in python

查看:114
本文介绍了在蟒蛇中的Appengine上的通配符搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Google App Engine构建联系人数据库。

例如,我可以查询('name =',%ewman%)吗?


不幸的是,Google应用引擎无法进行部分文字匹配。 来自文档:


提示:查询过滤器没有显式匹配字符串值的一部分,但可以使用不等式过滤器伪造前缀匹配项:



  db.GqlQuery(SELECT * FROM MyModel WHERE prop> =:1 AND prop <:2,abc,uabc + u\\\�)




这匹配每个MyModel实体带有以字符abc开头的字符串属性prop。 unicode字符串u\\\\\\\\\\\\表示最大可能的Unicode字符当属性值在索引中排序时,落在此范围内的值都是以给定前缀开头的值。



I'm just starting with Python on Google App Engine building a contact database. What is the best way to implement wildcard search?

For example can I do query('name=', %ewman%)?

解决方案

Unfortunately, Google app engine can't do partial text matches

From the docs:

Tip: Query filters do not have an explicit way to match just part of a string value, but you can fake a prefix match using inequality filters:

db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND prop < :2", "abc", u"abc" + u"\ufffd")

This matches every MyModel entity with a string property prop that begins with the characters abc. The unicode string u"\ufffd" represents the largest possible Unicode character. When the property values are sorted in an index, the values that fall in this range are all of the values that begin with the given prefix.

这篇关于在蟒蛇中的Appengine上的通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆