Skip to content

Conversation

@jimczi
Copy link
Contributor

@jimczi jimczi commented Mar 30, 2017

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.

@jimczi jimczi added :Internal :Search/Search Search-related issues that do not fall into other categories v5.4.0 v6.0.0-alpha1 labels Mar 30, 2017
@jimczi jimczi requested a review from jpountz March 30, 2017 16:49
Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

?

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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

if (nested != null ||
(sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) ||
(source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) {
return new SortField(getFieldName(), source, reverse);
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it was here before already, but I think we can remove this cast?

jimczi added 3 commits April 3, 2017 09:01
…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.
@jimczi jimczi force-pushed the simple_sort_field branch from 813d9fa to d844e98 Compare April 3, 2017 07:56
@jimczi jimczi merged commit 7316b66 into master Apr 3, 2017
@jimczi jimczi deleted the simple_sort_field branch April 3, 2017 07:57
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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search/Search Search-related issues that do not fall into other categories v5.4.0 v6.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants