2010-09-17 66 views
0

这是我的代码:如何获取其中包含“SSS”,而不是“=”,在信息

class Marker_latlng(db.Model): 
    geo_pt = db.GeoPtProperty() 

class Marker_info(db.Model): 
    info = db.StringProperty() 
    marker_latlng =db.ReferenceProperty(Marker_latlng) 

q = Marker_info.all() 
q.filter("info =", "sss") 

,但如何获得包含“SSS”,而不是“=”的信息,

有一个像“包含”的方法?

+0

可能的重复:http://stackoverflow.com/questions/3172292/gql-find-all-entities-that-c​​ontain-a-substring – geoffspear 2010-09-17 03:18:12

回答

1

而不是使用一个StringProperty的,你可以使用一个StringListProperty。在保存信息字符串之前,将它分成包含每个单词的字符串列表。

然后,当您使用q.filter("info =", "sss")时,它将匹配任何包含"sss"的单词的项目。

对于更一般的事情,您可以查看应用引擎全文搜索。

+1

请注意,无论如何,您将被限制为关键字搜索或关键字前缀搜索;没有好的方法来进行真正的子字符串搜索。 – geoffspear 2010-09-17 10:44:50

相关问题