What is a good pattern for inexact queries in the Google App Engine Datastore?

北慕城南 提交于 2019-12-03 20:19:56

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

You could store a soundex http://effbot.org/librarybook/soundex.htm version of the name in the datastore. Then, to query a name, soundex the query, and look that up.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!