0

我正在尝试使用大 number_found_accuracy 按“updated_at”字段运行查询和排序:

order_options = search.SortOptions(
    expressions=[search.SortExpression(expression='updated_at',
                                   direction=search.SortExpression.DESCENDING)])

query_options = search.QueryOptions(
    limit=50,
    cursor=search.Cursor(),
    sort_options=order_options,
    number_found_accuracy=25000)

index = search.Index('contacts', namespace='default')
query_future = index.search_async(search.Query("", options=query_options))
contacts = query_future.get_result()

当 get_result() 被调用时,我得到以下错误:

调用rv = self.handle_exception (request, response, e ) 文件“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,第 1529 行,调用 rv = self.router.dispatch(request,响应)文件“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,第 1278 行,在 default_dispatcher 返回 route.handler_adapter(请求,响应)文件“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2。py",第 1102 行,在称呼 返回 handler.dispatch() 文件“/base/data/home/apps/p~imobzi-app/20181127t101400.414282042583891084/modules/base_handler.py”,第 72 行,在 dispatch super(BaseHandler, self).dispatch() 文件中“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,第572行,在调度返回self.handle_exception(e,self.app.debug )文件“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,第570行,在调度返回方法(*args,**kwargs)文件“/base/data/home/apps/p~imobzi-app/20181127t101400.414282042583891084/main.py”,第 132 行,在 get contacts = query_future.get_result() 文件中“/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/1/google/appengine/api/search/search.py​​”,第 281 行,在 get_result 中引发 _ToSearchError(e) TransientError:临时搜索服务错误

当查询结果很大时,当我在同一查询中使用“number_found_accuracy”和“sort_options”时会发生错误(此查询返回超过 50,000 个结果)。

如果从 query_options 中删除“number_found_accuracy”或“sort_options”,我通常会得到结果,但如果两者都在 query_options 中,则会发生错误。

在正常情况下,我会从查询中删除“number_found_accuracy”,但我需要为用户显示结果计数并按 updated_at 字段对其进行排序。有谁知道解决这个问题的方法?仅当将项目部署到服务器,在本地/开发环境中,一切都按预期工作时,才会发生这种情况。

4

1 回答 1

0

此错误的一个原因可能是查询的长度超过了文档中指定的 2000 个字符的限制。

排序也有一个限制,可以通过使用 Document rank 对索引中的文档进行预排序来解决,如StackOverflow answer中所述。

另请注意,根据文档

number_found:
返回与查询匹配的文档的大致数量。QueryOptions 定义搜索结果的后处理。如果 QueryOptions.number_found_accuracy 参数设置为 100,则 number_found <= 100 是准确的。

由于您已设置number_found_accuracy=25000,任何大小大于 25000 的搜索结果都将是近似值。

于 2018-11-27T18:13:07.013 回答