[英]Using Search API Python - Google App Engine Big Table
I would like to use Search API with an application that is already using a defined model ( db.Model
). 我想将Search API与已经使用定义的模型(
db.Model
)的应用程序一起使用。
For example, suppose that my model looks like this: 例如,假设我的模型如下所示:
class Greeting(db.Model): author = db.StringProperty() content = db.StringProperty() date = db.DateTimeProperty()
Now how do I use the Search API to query the Greeting
entity? 现在如何使用Search API查询
Greeting
实体?
I have read the documentation but honestly I don't understand that. 我已经阅读了文档,但老实说我不明白。
Please give me a very simple example. 请给我一个非常简单的例子。
You don't. 你不知道
The search API needs to search "documents" that you have created, not models from the datastore. 搜索API需要搜索您创建的“文档”,而不是数据存储中的模型。
You'll have to write a converter that loads data from your models and creates searchable documents that can then be put into the index. 您将必须编写一个转换器,该转换器从模型中加载数据并创建可搜索的文档,然后将其放入索引中。
EG from the docs to create a document: 从文档EG创建文档:
from google.appengine.api import search
search.Document(
doc_id='document id',
fields=[search.TextField(name='subject', value='going for dinner'),
search.HtmlField(name='body', value='<html>I found a place.</html>'),
search.TextField(name='signature', value='brzydka pogoda', language='pl')],
language='en')
So that document has 3 separate fields that can be searched individually. 因此该文档具有3个单独的字段,可以分别进行搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.