Google App引擎搜索API游标无法更新

时间:2013-09-04 11:54:17

标签: python google-app-engine

我正在使用游标从GAE全文搜索API获取结果。问题在于光标在每次迭代中保持相同:

cursor = search.Cursor()
files_options = search.QueryOptions(
    limit=5,
    cursor=cursor,
    returned_fields='state'
)

files_dict = {}
query = search.Query(query_string=text_to_search, options=files_options)
index = search.Index(name='title')
while cursor != None:
    results = index.search(query)
    cursor = results.cursor

即使搜索仅返回18个结果,光标也不会变为无

1 个答案:

答案 0 :(得分:3)

问题是你一遍又一遍得到相同的5个结果。每次在循环中执行results = index.search(query)时,都会检索前五个结果,因为查询选项指定的限制为5并且空光标。您需要创建一个新查询,在每次迭代时启动新游标。

cursor = search.Cursor()
index = search.Index(name='title')

while cursor != None:
    options = search.QueryOptions(limit=5, cursor=cursor, returned_fields='state'))
    results = index.search(search.Query(query_string=text_to_search, options=options))
    cursor = results.cursor

请查看此页面的简介部分:https://developers.google.com/appengine/docs/python/search/queryclass