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.
You don't.
The search API needs to search "documents" that you have created, not models from the datastore.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With