Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible#23827
Merged
Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible#23827
Conversation
jpountz
approved these changes
Mar 31, 2017
Contributor
jpountz
left a comment
There was a problem hiding this comment.
This looks great. Before pushing, could you leave some inline comments in the sortField impls to explain the rationale of not using the comparatorsource approach all the time?
| throw new UnsupportedOperationException("no global ordinals sorting yet"); | ||
| public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { | ||
| return null; | ||
| } |
| XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); | ||
| if (nested != null || | ||
| (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || | ||
| (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { |
Contributor
There was a problem hiding this comment.
can you indent the content of the if statement and the content of the block at different levels, otherwise I find it a bit hard to read
| if (nested != null | ||
| || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MAX) | ||
| || numericType == NumericType.HALF_FLOAT) { | ||
| return new SortField(fieldName, source, reverse); |
| if (nested != null || | ||
| (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || | ||
| (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { | ||
| return new SortField(getFieldName(), source, reverse); |
| public org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource comparatorSource(Object missingValue, MultiValueMode sortMode, Nested nested) { | ||
| return new BytesRefFieldComparatorSource((IndexFieldData<?>) this, missingValue, sortMode, nested); | ||
| public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { | ||
| XFieldComparatorSource source = new BytesRefFieldComparatorSource((IndexFieldData<?>) this, missingValue, sortMode, nested); |
Contributor
There was a problem hiding this comment.
I know it was here before already, but I think we can remove this cast?
…rtField when possible
Currently for field sorting we always use a custom sort field and a custom comparator source.
Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField unless
the field is nested especially since we removed the FieldData for numerics.
We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested.
This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom
sort field when the field sort spec is not handled by the SortedSortFields.
813d9fa to
d844e98
Compare
jimczi
added a commit
that referenced
this pull request
Apr 3, 2017
…rtField when possible (#23827) Currently for field sorting we always use a custom sort field and a custom comparator source. Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField unless the field is nested especially since we removed the FieldData for numerics. We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested. This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom sort field when the field sort spec is not handled by the SortedSortFields.
jasontedor
added a commit
to jasontedor/elasticsearch
that referenced
this pull request
Apr 3, 2017
* master: (137 commits) CONSOLEify the "using scripts" documentation Adds tests for cardinality and filter aggregations Add Backoff policy to azure repository Revert "Adds tests for cardinality and filter aggregations (elastic#23826)" Adds tests for cardinality and filter aggregations (elastic#23826) mute testDifferentRolesMaintainPathOnRestart Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible (elastic#23827) Prevent nodes from joining if newer indices exist in the cluster (elastic#23843) Synchronized CollapseTopFieldDocs with lucenes relatives (elastic#23854) CONSOLEify analysis docs Adapted search_shards rest test to work with Perl To examine an exception in rest tests, the exception should be caught, not ignored Fixed bad YAML in rest tests Fix BootstrapForTesting blowup Ban Boolean#getBoolean Fix language in some docs CONSOLEify lang-analyzer docs Stricter parsing of remote node attribute Fix cross-cluster remote node gateway attributes FieldCapabilitiesRequest should implements Replaceable since it accepts index patterns ...
jasontedor
added a commit
to jasontedor/elasticsearch
that referenced
this pull request
Apr 4, 2017
* master: (146 commits) Introduce single-node discovery Await termination after shutting down executors Fix initialization issue in ElasticsearchException Fix bulk queue size in thread pool docs [DOCS] Remove line about eager loading global ordinals GceDiscoverTests - remove intitial_state_timeout SpecificMasterNodesIT shouldn't use autoMinMasterNodes testRestorePersistentSettings doesn't to mess with discovery settings testDifferentRolesMaintainPathOnRestart shouldn't use auto managing of min master nodes CONSOLEify the "using scripts" documentation Adds tests for cardinality and filter aggregations Add Backoff policy to azure repository Revert "Adds tests for cardinality and filter aggregations (elastic#23826)" Adds tests for cardinality and filter aggregations (elastic#23826) mute testDifferentRolesMaintainPathOnRestart Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible (elastic#23827) Prevent nodes from joining if newer indices exist in the cluster (elastic#23843) Synchronized CollapseTopFieldDocs with lucenes relatives (elastic#23854) CONSOLEify analysis docs Adapted search_shards rest test to work with Perl ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently for field sorting we always use a custom sort field and a custom comparator source.
Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField (unless the field is nested) especially since we removed the FieldData for numerics.
We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested.
This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom sort field when the field sort spec is not handled by the SortedSortFields.