Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the sorting for terms aggs, #5237

Closed
wants to merge 2 commits into from
Closed

Conversation

thanodnl
Copy link
Contributor

This pull request fixes the sorting of aggregations as discussed in issue #5236.

It forces the NaN values to be pushed to the bottom of the list, no matter if you are sorting asc/desc. This way top lists show the most relevant aggregates in the top. Also it actually does what the comments above it already said it should do.

Closes #5236.

return asc ? 1 : -1;
if (Double.isNaN(v1)) {
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should even be

if (Double.isNaN(v1)) {
    if (Double.isNaN(v2)) {
        return 0;
    } else {
        return 1;
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (Double.isNaN(v1)) {
    return Double.isNaN(v2) ? 0 : 1;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suggestion of @uboness is more readable than the extra if-statement and indents. I'll change it to that one for a complete implementation of the comparator contract.

Thnx

@jpountz
Copy link
Contributor

jpountz commented Feb 24, 2014

The fix look good. Can you write a unit test for this? (If that looks complicated to you, I can take care of this, just let me know!)

@thanodnl
Copy link
Contributor Author

I've been looking into the test, but I find it hard to see where to add what :).

I found StringTermsTests (and my changes didn't break it) where some tests for terms aggregations are, including sorting on sub aggregate. But for this test I need to change the source dataset in a way I cannot really comprehense.

Would you mind adding a test?

@jpountz
Copy link
Contributor

jpountz commented Feb 24, 2014

Indeed, this would be easier to have a different test case.

Would you mind adding a test?

Sure, I will work on it!

@uboness
Copy link
Contributor

uboness commented Feb 25, 2014

left one comment... other than that LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terms aggregations order wrong when sorting NaN's
4 participants