在Google App Engine数据存储区中搜索以前缀开头的字符串 [英] Search a string beginning with a prefix in Google App Engine Datastore

查看:75
本文介绍了在Google App Engine数据存储区中搜索以前缀开头的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要搜索名称以特定字符串开头的所有实体,这在数据存储区中可以吗?

I want to search all entities whose name starts with a specific string, is this possible in Datastore?

我已经尝试过了:

q = datastore.NewQuery("Places").Filter("Name > ", "a")

但这是行不通的.

如果这不可能,那么您可以向我建议什么替代解决方案? BigQuery? BigTable或App Engine上的其他服务?

If this is not possible, what alternative solution can you suggest to me? BigQuery? BigTable or other services on App Engine?

推荐答案

这是可能的,但是可以结合使用2个不等式过滤器.

This is something that is possible, but with a combination of 2 inequality filters.

假设您要列出具有"li"前缀的Places.这可以用查询来描述,该查询列出了大于(或等于)"li" 小于"li"的前一个前缀,该前缀是按字典顺序在"li"之后的下一个字符串: c5>.

Let's say you want to list Places that have the "li" prefix. This can be described with a query that lists Places that are greater than (or equal to) "li" and less than a prefix that is the next string after "li" in lexicographical order: "lj".

这是GQL的样子:

SELECT * FROM Places WHERE Name > 'li' AND Name < 'lj'

在Go中编码为:

q = datastore.NewQuery("Places").Filter("Name >", "li").Filter("Name <", "lj")

这将列出Places,其中名称为:

This will list Places where name is for example:

liam
lisotto
lizst

但将排除以下名称:

abc
ljoi
lj
qwerty

需要注意的一件事:小写字母和大写字母在字典顺序上是不同的,例如,"List"小于"li"(即使"list"大于"li")!

One thing to note: small and capital letters are different in lexicographical order, so for example "List" is less than "li" (even though "list" is greater than "li")!

这篇关于在Google App Engine数据存储区中搜索以前缀开头的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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