简体   繁体   中英

Google Appengine Search API to Datastore Query

I construct the Search API data like

search.SearchResults(
results=
[
search.ScoredDocument(doc_id=u'4873035534303232', fields=[search.TextField(name=u'name', value=u'a'), search.TextField(name=u'description', value=u'b'), search.DateField(name=u'date', value=datetime.datetime(2015, 2, 16, 7, 21, 58, 188000)), search.TextField(name=u'author', value=u'test@example.com')], language=u'en', rank=130231318L), 
search.ScoredDocument(doc_id=u'5717460464435200', fields=[search.TextField(name=u'name', value=u'a b c'), search.TextField(name=u'description', value=u'c d e'), search.DateField(name=u'date', value=datetime.datetime(2015, 2, 16, 7, 21, 25, 965000)), search.TextField(name=u'author', value=u'test@example.com')], language=u'en', rank=130231285L), 
search.ScoredDocument(doc_id=u'5506354231902208', fields=[search.TextField(name=u'name', value=u'How about today?'), search.TextField(name=u'description', value=u"it's good"), search.DateField(name=u'date', value=datetime.datetime(2015, 2, 16, 7, 10, 13, 608000)), search.TextField(name=u'author', value=u'test@example.com')], language=u'en', rank=130230613L)
],
number_found=3L)

I didn't insert the blobKey to Search API, then I need to query of Datastore to get the blobKey. Each ndb article has a same doc_id as a ID.

So when I get the response of Search API, I have to query 3 times for

doc_id=u'4873035534303232', doc_id=u'5717460464435200', doc_id=u'5506354231902208'

I think this process is so bad. Quota will be exceed soon. Do you have any other solution?

Use ndb.get_multi or just de-normalize that data and store it in the search API for faster access.

ndb.get_multi will use single batch to get all keys and use only N read operations. (0.05 Million Ops is Free)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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