我基本上想使用 MatchScore 对我的文档进行排序,但是, boost 那些有图像的文档。
为此,我的方法是在文档中添加一个具有 boost 值的字段,然后将该值乘以文档 _score。
问题是,使用以下代码我无法实现基于两个值的乘积对文档进行排序。搜索 API 返回按 _score 排序的文档,而不是我传递的 SortOptions 表达式。
sort_opts = SortOptions(
match_scorer=search.MatchScorer(),
expressions=[
search.SortExpression(
expression='_score * has_img',
direction=search.SortExpression.DESCENDING,
default_value=0.0
)
]
)
options = QueryOptions(
limit=10,
sort_options=sort_opts,
returned_expressions=[
FieldExpression('score', '_score * has_img'),
FieldExpression('normalscore', '_score * 1')
]
)
index = search.Index(name='Search', namespace='search')
results = index.search(
query=Query(
query_string=search_query,
options=options
)
)
如您所见,为了进行调试,我返回了我想要作为排序依据的分数以及默认分数。它们会返回正确的值,但是,文档仍按默认分数排序。
对我做错了什么有什么想法吗?
最佳答案
如上所述:
I had the same problem, and it seems like a GAE bug. The only way around I found was to use the built-in _rank field (see query and sorting options). The basic idea is to set the _rank field of your document to a value that represents "having an image"
关于google-app-engine - GAE 搜索 API 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19893840/