【问题标题】:Query by multiple doc_ids in Google App Engine Search APIGoogle App Engine Search API 中的多个 doc_id 查询
【发布时间】:2017-01-04 04:52:32
【问题描述】:

我想从 doc_ids 列表中检索文档列表。类似于在 SQL 中执行以下操作:

SELECT * FROM Documents WHERE id IN (1,2,3,167,91)

我在documentation 中看到了这个方法,但它只检索一个文档。为了效率,我想做批量检索。这可能吗?

【问题讨论】:

    标签: google-app-engine google-app-engine-python


    【解决方案1】:

    我认为没有批处理 get 函数,但有一个异步版本(搜索 https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.search.search 以获得 get_async),因此您可以执行类似(未经测试的伪代码):

    # query for docs ids in advance
    futures = []
    for id_ in doc_ids:
        futures.append(index.get_async(id_))
    
    # dereference the futures when you need them
    ids = [x.get_result() for x in futures]
    

    【讨论】:

      猜你喜欢
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多