GQL查询(GAE datastore Python):如何检索具有相同标记的所有实体以及包含子字符串的所有实体?
我有一个双语词典数据库,存储在GAE中,有60000对,如下所示: 日期、标签、价值 日期,维斯,螺丝钉 日期,vis,螺钉 日期,相对于bois,木螺钉 日期,相对于pointu,圆锥头螺钉 日期,相对于黄铜,钎焊螺钉 日期,相对于métaux,机器螺钉 现在使用以下python脚本:GQL查询(GAE datastore Python):如何检索具有相同标记的所有实体以及包含子字符串的所有实体?,python,google-cloud-datastore,gql,Python,Google Cloud Datastore,Gql,我有一个双语词典数据库,存储在GAE中,有60000对,如下所示: 日期、标签、价值 日期,维斯,螺丝钉 日期,vis,螺钉 日期,相对于bois,木螺钉 日期,相对于pointu,圆锥头螺钉 日期,相对于黄铜,钎焊螺钉 日期,相对于métaux,机器螺钉 现在使用以下python脚本: def get_value(self, tag): entry = db.GqlQuery("SELECT * FROM StoredData where tag = :1", tag).get()
def get_value(self, tag):
entry = db.GqlQuery("SELECT * FROM StoredData where tag = :1", tag).get()
value = entry.value
value = unicode(value)
value = value.encode('ascii','xmlcharrefreplace')
如果我要求vis,我只会得到螺丝钉回应
问题:
我还想得到第二个答案,即检索具有相同标记的所有实体
我还希望获得包含子字符串螺钉的所有实体,由用户键入至少3个字符:
螺钉,螺钉,木螺钉,锥形螺钉,钎焊螺钉,机螺钉
=>为了在该脚本生成的表中显示它们,我必须进行哪些GQL查询
### Show the tags and values as a table.
###def show_stored_data(self):
### self.response.out.write('''
### <p><table border=1>
### <tr>
### <th>Key</th>
### <th>Value</th>
### <th>Created (GMT)</th>
### </tr>''')
### entries = db.GqlQuery(" ***GQL query n°1 or n°2*** ")
### for e in entries:
### entry_key_string = str(e.key())
### self.response.out.write('<tr>')
### self.response.out.write('<td>%s</td>' % e.tag)
### self.response.out.write('<td>%s</td>' % e.value)
### self.response.out.write('<td><font size="-1">%s</font></td>\n' % e.date.ctime())
### self.response.out.write('''
### <td><form action="/deleteentry" method="post"
### enctype=application/x-www-form-urlencoded>
### <input type="hidden" name="entry_key_string" value="%s">
### <input type="hidden" name="tag" value="%s">
### <input type="hidden" name="fmt" value="html">
### <input type="submit" style="background-color: red" value="Delete"></form></td>\n''' %
### (entry_key_string, e.tag))
### self.response.out.write('</tr>')
### self.response.out.write('</table>')
非常感谢你的帮助
菲利普只得到一个结果
是您的问题是您正在GqlQuery对象上使用.get方法。文件说:
调用查询的get方法,以获取在数据存储中找到的第一个匹配实体:
如果您这样做:
def get_valueself,标签:
entries=db.GqlQuerySELECT*来自StoredData,其中tag=:1,tag.get
对于条目中的条目:
value=entry.value
价值=贬值
value=value。编码为“ascii”,“xmlcharrefreplace”
打印值
我希望你会看到你会得到螺丝钉和螺丝钉
子串
至于用螺丝抓住所有的绳子,这将比你预想的要困难得多。看一看。一些答案建议您使用
例如visá,您知道短语总是以所讨论的子标记开头,您可能可以使用>进行操作,听起来像是希望进行全文搜索:而不是直接搜索。看到你的答案在:/非常感谢你的答案非常有用。我终于有时间在我的网站上运行了。菲利浦我很高兴这有帮助。如果你的问题得到了回答,请接受最好的答案,这样问题就可以结束了。非常感谢你的回答,非常有帮助。我终于有时间在我的网站上运行了。菲利普