简体   繁体   English

App Engine搜索API - 排序结果

[英]App Engine Search API - Sort Results

I have several entities that I am searching across that include dates, and the Search API works great across all of them except for one thing - sorting. 我有几个实体,我正在搜索包括日期,并且搜索API在所有这些实体中运行良好,除了一件事 - 排序。

Here's the data model for one of my entities (simplified of course): 这是我的一个实体的数据模型(当然简化):

class DepositReceipt(ndb.Expando):
    #Sets creation date
    creation_date = ndb.DateTimeProperty(auto_now_add=True)

And the code to create the search.Document where de is an instance of the entity: 以及创建search.Document的代码,其中de是实体的实例:

document = search.Document(doc_id=de.key.urlsafe(),
    fields=[search.TextField(name='deposit_key', value=de.key.urlsafe()),
            search.DateField(name='created', value=de.creation_date),
            search.TextField(name='settings', value=de.settings.urlsafe()),
            ])

This returns a valid document. 这将返回有效的文档。


And finally the problem line. 最后问题就行了。 I took this snippet from the official GAE Search API tutorial and just changed the direction of the sort to DESCENDING and changed the search expression to created (the date property from the Document above). 我从官方GAE Search API教程中获取了此片段,并将排序方向更改为DESCENDING ,并将搜索表达式更改为已created (上述Document的日期属性)。

expr_list = [search.SortExpression(
    expression="created", default_value='',
    direction=search.SortExpression.DESCENDING)]

I don't think this is important, but the rest of the search code looks like this: 我不认为这很重要,但搜索代码的其余部分如下所示:

sort_opts = search.SortOptions(expressions=expr_list)

query_options = search.QueryOptions(
    cursor=query_cursor,
    limit=_NUM_RESULTS,
    sort_options=sort_opts)  

query_obj = search.Query(query_string=query, options=query_options)

search_results = search.Index(name=index_name).search(query=query_obj)

In production, I get this error message: 在生产中,我收到此错误消息:

InvalidRequest: Failed to parse search request "settings:ag5zfmdoaWRvbmF0aW9uc3IQCxIIU2V0dGluZ3MYmewDDA"; failed to parse date

Changing the expression="created" to anything else works perfectly fine. expression="created"更改为其他任何内容都非常正常。 This also happens across my other entity types that use dates, so I have no idea what's going on. 这也发生在我使用日期的其他实体类型中,因此我不知道发生了什么。 Advice? 建议吗?

我认为default_value需要是一个有效的日期,而不是''你拥有它”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM