Skip to content

Result order is not preserved with records adapters (Mongoid in my case). #99

Closed
@dwkoogt

Description

@dwkoogt

Hi.
Let say i have two records and I'm running a query such that the order of the resulting records are reversed. I'm running a simple function score query and I can see that record #2 has higher score than record #1 (in response.response). But when I get the records, the result order is back to natural order. I tried to show the records' scores with each_with_hit function and saw that the scores are switched. I looked into the code and saw two problems. In the adapter code, it's using $in query for array of ids. I believe mongo returns results in natural order unless sort is defined. It will not return the results with the ids' array order. Then in the records class, this db result ( #1, #2) is zipped with elasticsearch result (#2, #1). Hence the scores get switched.

fyi
https://jira.mongodb.org/browse/SERVER-7528

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions