GQL:查找包含子字符串的所有实体
我有一些具有 StringProperty 的实体,我想查询与子字符串匹配的所有实体。有没有办法只使用 GQL 来做到这一点?
例如,如果我的数据存储如下所示:
ID/Name question_text
--------------------------------------------------------------
3001 I like to eat chicken.
3020 I only like to eat chicken that is deep fried.
3045 I like filet mignon.
3052 I like cheese.
GQL 查询将如何查找 Question_text 中包含“chicken”的所有实体?
I have some entities that have a StringProperty and I would like to query for all the entities that match a substring. Is there a way to do that using just GQL?
For example, if my datastore looks like this:
ID/Name question_text
--------------------------------------------------------------
3001 I like to eat chicken.
3020 I only like to eat chicken that is deep fried.
3045 I like filet mignon.
3052 I like cheese.
What would the GQL query be to find all the entities that contain 'chicken' in question_text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是对 StringProperty 的全文搜索。这就是创建 SearchableModel 的内容为了。
基本上,它使用任务队列在您的实体上创建一个新属性,该属性是文本字段中所有字符串(我相信二元组和三元组)的列表。然后,通过 GQL 查询搜索“chicken”,例如
SELECT * FROM What WHERE 'chicken' IN strings_list
What you're looking for is full-text search over a StringProperty. This is what SearchableModel was created for.
Basically, it creates a new property on your entity that is a list of all the strings (and I believe bi- and tri-grams) in the text field, using the task queue. Then searching for "chicken" is done by a GQL query like
SELECT * FROM whatever WHERE 'chicken' IN strings_list