2012-06-21 23 views
0

在我的業務邏輯中,我首先需要檢查Appengine Search API索引是否存在。如果它存在,我然後確定長度。確定搜索API索引是否存在

for index in search.list_indexes(fetch_schema=False): 
    if name == index.name: 
     indexed = True 

問題是整個列表沒有被返回。所以我嘗試了以下幾點:

for index in search.list_indexes(fetch_schema=False, limit=500): 
    logging.info("sent name: " + name + " : official index name: " + index.name) 

結果是它限制了100個指標。我肯定錯過了什麼。

我的問題是雙重的:

  1. 是否有更好的方法來檢查一個索引是否存在? (我的方式感覺不對)

  2. 爲什麼list_indexes只能返回100,當我們明顯有更多?

編輯:-----------------------------------------

基於@ skreft的建議,我更新了我的代碼如下:

for index in search.list_indexes(fetch_schema=False, include_start_index=True, start_index_name="some_index", limit=1000): 
     logging.info("sent name: " + name + " : official index name: " + index.name) 
     if name == index.name: 
      indexed = True`enter code here` 

但問題是,我得到一個非常神祕的錯誤消息,我跟着文檔相當明確。其他人有這種情況嗎? (下面的錯誤):

Traceback (most recent call last): 
    File "/base/data/home/apps/s~searchbertha-hrd/82.359784956262345840/models.py", line 1898, in build_searchable_index 
    for index in search.list_indexes(fetch_schema=False, include_start_index=True, start_index_name=name, limit=1000): 
    File "/base/python_runtime/python_lib/versions/1/google/appengine/api/search/search.py", line 675, in list_indexes 
    raise _ToSearchError(e) 
InvalidRequest 

回答

0

嘗試使用參數start_index_name和include_start_index。

查看docs瞭解更多信息。

+0

感謝您的建議。我試過了,並在上面編輯了我的問題。我難住了一個非常神祕的_ToSearchError(e)消息。思考? – user1453956

+0

嘗試將限制更改爲100.這對我有效。另外,在你的情況下,我認爲使用index_name_prefix更合適。 –

+0

index_name_prefix做了訣竅。非常感謝。 – user1453956