Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

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?

I have read the documentation but honestly I don't understand that.

Please give me a very simple example.

like image 533
gather Avatar asked Nov 09 '12 09:11

gather


1 Answers

You don't.

The search API needs to search "documents" that you have created, not models from the datastore.

  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.

E.G. from the docs to create a document:

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.

The Document Class

like image 173
Paul Collingwood Avatar answered Oct 03 '22 08:10

Paul Collingwood