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

Refactor Indexable\Term::parse_orderby() and remove refs to non-existent .long fields #2421

Merged
merged 2 commits into from
Oct 21, 2021

Conversation

felipeelia
Copy link
Member

Description of the Change

This PR fixes a bug in terms' sort, where non-existent fields term_group.long and count.long were used causing ES to fail. It also refactor the method a bit, making it smaller and, hopefully, easier to understand.

Although this PR updates some tests, we should implement a new test really triggering those queries, in addition to check if the code parsed them correctly.

Changelog Entry

Fixed: Sort by count and tem_group on Terms

Comment on lines 978 to 981
$es_field_name = 'name.sortable';

if ( version_compare( $es_version, '7.0', '>=' ) ) {
$sort[] = array(
'name.sortable' => array(
'order' => $order,
),
);
$es_field_name = 'name.sortable';
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we check only if $es_version is less than 7.0? And if true, change it to name.raw.

'order' => $order,
),
);
$es_field_name = 'meta.' . $args['meta_key'] . '.value';
Copy link
Contributor

Choose a reason for hiding this comment

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

If we enter in this case and the if condition fails, we would never set the $es_field_name variable, wouldn't we? In this case, wouldn't be an issue in line 1027?

'order' => $order,
),
);
$es_field_name = 'meta.' . $args['meta_key'] . '.long';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the same behavior as the previous comment.

@felipeelia felipeelia merged commit 2242303 into develop Oct 21, 2021
@felipeelia felipeelia deleted the fix/terms-sort branch October 21, 2021 15:02
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.

2 participants