Reputation: 2738
I basically want to sort my documents using the MatchScore, but, boost those that have an image.
To do this, my approach is to add a field to the document with the boosting value, and then multiply this value by the document _score.
The problem is, that with the following code I cannot achieve to sort the documents based on the multiplication of both values. Search API returns the documents sorted by _score instead of the SortOptions expression I pass.
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
)
)
As you may see, for debugging I return both the score I want to sort by, as well as the default score. They but return correct values, however, documents are still sorted by the default score.
Any ideas of what I'm doing wrong?
Upvotes: 5
Views: 632
Reputation: 24637
As noted above:
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"
Upvotes: 0