GQL: Find all entities that contain a substring

蓝咒 提交于 2019-12-11 00:05:37

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/3172292/gql-find-all-entities-that-contain-a-substring

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