google-app-engine:查询模型中的字符串属性不会检索结果

标签 google-app-engine gql

我有一个模型,表示为

class Suggestion(db.Model):
    text = db.TextProperty()
    votes = db.IntegerProperty()
    time_added = db.DateTimeProperty(auto_now_add=True)
    time_modified = db.DateTimeProperty(auto_now=True)

我添加了一个建议

suggestion = Suggestion(text='Adding Suggestion', votes=1)
suggestion.put()

我看到该值已插入,现在我想通过查询文本属性来获取此建议。我做了以下事情

from models import Suggestion
suggestion = Suggestion.all().filter('text = ', 'Adding Suggestion').fetch(1)[0]
print suggestion

结果为空。我怎样才能使这个查询工作?

谢谢

最佳答案

这是由于文本属性不能在过滤器中使用。 http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#TextProperty

Unlike StringProperty, a TextProperty value can be more than 500 characters long. However, TextProperty values are not indexed, and cannot be used in filters or sort orders

有一些替代方法可以做到这一点。

  1. 如果“文本”短于 500 个字符,那么您可以使用 StringProperty。 StringProperty可以在过滤器中使用。
  2. 尝试针对 Google 应用引擎的第 3 方全文搜索方法。 http://code.google.com/p/guestbook-example-appengine-full-text-search/
  3. 应用引擎团队正在努力在不久的将来提供全文搜索功能。 http://googleappengine.blogspot.com/2012/01/happy-birthday-high-replication.html

编辑

全文功能由Google App Engine团队开发: https://developers.google.com/appengine/docs/python/search/overview

关于google-app-engine:查询模型中的字符串属性不会检索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8957910/

相关文章:

android - gradlew appengineEndpointsInstallClientLibs不会安装客户端库(但会生成它们)

java - 很棒的字体+应用程序引擎不工作

Python:GQuery 结果集(GQL、GAE)上的 DISTINCT

python - 将字符串变量传递给 gql 查询

python - GQL 请求 BadArgument 错误。如何处理我的案子?

python - 更改实体的键名

java - 带有 Uibinder 或替代品的 FlexTable

google-app-engine - 在 AppEngine 上使用 Go 连接到第二代 Google SQL Cloud

google-app-engine - 在 GQL 中计算结果的最佳方法是什么?

python - 在python中向预先存在的字典键添加一个值