python - Google App引擎搜索API光标不更新

标签 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 个结果,光标也不会变为 None

最佳答案

问题是您一次又一次地得到相同的 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

关于python - Google App引擎搜索API光标不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18613150/

相关文章:

python - 将 eval() 与 undefined variable 一起使用

python - Numpy isnan() 在 float 组上失败(来自 pandas 数据框应用)

java - com.google.api.client.googleapis.auth.oauth2.GoogleCredential 现已弃用

python - Google App EngineSearch API 中的分页

python - AppEngine 上的 AppAssertionCredentials : how to impersonate user account?

python:像整数一样的 float

python - 转换为自定义色彩空间

python - 创建一个空字典,键是可变维度的元组

java - 在 JPA 中检索实体性能

google-app-engine - 谷歌应用程序引擎中的 JDO 除了类型 "Key"键之外的其他主键可能吗?