Google App Engine数据存储区中的不精确查询有什么好的模式? [英] What is a good pattern for inexact queries in the Google App Engine Datastore?
问题描述
从文档中引用:
提示:查询过滤器没有明确的方式来匹配字符串值的一部分,但您可以使用不等式过滤器伪造前缀匹配项:
db.GqlQuery(SELECT * FROM MyModel WHERE prop> = 1 AND prop <:2,abc,uabc+ u\\\�)
这会将每个MyModel实体与字符串属性prop匹配,并以字符abc开头。 unicode字符串u\\\\\\\\\\\\表示最大可能的Unicode字符当属性值在索引中排序时,落在此范围内的值是以给定前缀开头的所有值。
http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html
另一种选择是SearchableModel,但是,我不认为它支持部分匹配。 href =http://billkatz.com/2008/8/A-SearchableModel-for-App-Engine =noreferrer> http://billkatz.com/2008/8/A-SearchableModel-for-App - 引擎
The Google App Engine Datastore querying language (gql) does not offer inexact operators like "LIKE" or even case insensitivity. One can get around the case sensitive issue by storing a lower-case version of a field. But what if I want to search for a person but I'm not sure of the spelling of the name? Is there an accepted pattern for dealing with this scenario?
Quoting from the documentation:
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.
http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html
Another option is the SearchableModel, however, i dont believe it supports partial matches.
http://billkatz.com/2008/8/A-SearchableModel-for-App-Engine
这篇关于Google App Engine数据存储区中的不精确查询有什么好的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!