【问题标题】:How to get all record's id in Search API using GAE如何使用 GAE 在 Search API 中获取所有记录的 ID
【发布时间】:2013-12-13 12:23:10
【问题描述】:
result = search.get_indexes(namespace='', offset=0, limit=999, start_index_name='f35cef2dfb9a8f34e381386ec5a1f7ee', include_start_index=True, fetch_schema=False)

但是,这里没有 id/index

如何在 Search API 中仅获取记录的 ID/索引? 救命!!

【问题讨论】:

    标签: google-app-engine python-2.7 gae-search


    【解决方案1】:

    上面的代码只会为您提供第一批 doc_ids,我必须花费数小时才能找到它。使用以下代码获取所有doc_ids...

    from google.appengine.api import search
    
    index = search.Index('YOUR_INDEX_NAME')
    document_ids = [document.doc_id for document in index.get_range(start_id="0", ids_only=True)]
        while len(document_ids)>1:
          for doc_id in document_ids:
            print doc_id# Do whatever you want with these ID's
          document_ids = [document.doc_id for document in index.get_range(start_id=doc_id, ids_only=True)]
    

    【讨论】:

      【解决方案2】:

      你可以使用 get_range 函数

      response = index.get_range(start_id="0", ids_only=True)

      https://developers.google.com/appengine/docs/python/search/indexclass#Index_get_range

      【讨论】:

        猜你喜欢
        • 2019-03-20
        • 1970-01-01
        • 2020-03-04
        • 1970-01-01
        • 2021-03-17
        • 2018-12-11
        • 2021-08-23
        • 2022-01-03
        • 2021-07-22
        相关资源
        最近更新 更多