Google App Engine数据存储区中的不精确查询有什么好的模式? [英] What is a good pattern for inexact queries in the Google App Engine Datastore?

查看:87
本文介绍了Google App Engine数据存储区中的不精确查询有什么好的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google App Engine数据存储查询语言(gql)不提供像LIKE这样不精确的操作符,甚至不区分大小写。可以通过存储小写字段的版本来解决区分大小写的问题。但是如果我想搜索一个人但是我不确定名字的拼写是什么?是否有可接受的模式来处理这种情况?

解决方案

从文档中引用:

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

  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屋!

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