code: public RowComparator comparator(Search search) {
          if (search != null) {
              if (search.usesSorting()) // Sort with search itself
              {
                  return new RowComparatorSorting(rowMapper, search.getSort());
              } else if (search.usesRelevance()) // Sort with row's score
              {
                  return new RowComparatorScoring(this);
              }
          }
          return rowMapper.naturalComparator();
      }
docs: Returns the {@link RowComparator} to be used for ordering the {@link Row}s obtained from the specified {@link
  Search}. This {@link Comparator} is useful for merging the partial results obtained from running the specified
  {@link Search} against several indexes.
  
  @param search A {@link Search}.
  @return The {@link RowComparator} to be used for ordering the {@link Row}s obtained from the specified {@link
  Search}.