简体   繁体   English

使用Search API Python-Google App Engine大表

[英]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需要搜索您创建的“文档”,而不是数据存储中的模型。

  1. Build documents structured with fields to describe the data you wish to search 构建带有字段的结构化文档以描述您要搜索的数据
  2. Create an index of documents you wish to search 创建您要搜索的文档索引
  3. Construct queries to search the index 构造查询以搜索索引
  4. Build search requests to run queries against the documents in your application Score results and customize their presentation to the user 建立搜索请求以对您的应用程序中的文档运行查询评分结果并为用户定制其表示形式

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个单独的字段,可以分别进行搜索。

The Document Class 文件类别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM