/** Returns the native sort type for {@link SortedSetSortField} and {@link SortedNumericSortField}, * {@link SortField#getType()} otherwise */ static SortField.Type getSortFieldType(SortField sortField) { if (sortField instanceof SortedSetSortField) { return SortField.Type.STRING; } else if (sortField instanceof SortedNumericSortField) { return ((SortedNumericSortField) sortField).getNumericType(); } else { return sortField.getType(); } }
switch (dvType) { case NUMERIC: if (sortField.getType().equals(SortField.Type.INT) == false && sortField.getType().equals(SortField.Type.LONG) == false && sortField.getType().equals(SortField.Type.FLOAT) == false && sortField.getType().equals(SortField.Type.DOUBLE) == false) { throw new IllegalArgumentException("invalid doc value type:" + dvType + " for sortField:" + sortField); if (sortField.getType().equals(SortField.Type.STRING) == false) { throw new IllegalArgumentException("invalid doc value type:" + dvType + " for sortField:" + sortField);
throw new IllegalArgumentException("unhandled SortField.getType()=" + sortField.getType());
@Override Sorter.DocComparator getDocComparator(int maxDoc, SortField sortField) throws IOException { assert sortField.getType().equals(SortField.Type.STRING); assert finalSortedValues == null && finalOrdMap == null &&finalOrds == null; int valueCount = hash.size(); finalSortedValues = hash.sort(); finalOrds = pending.build(); finalOrdMap = new int[valueCount]; for (int ord = 0; ord < valueCount; ord++) { finalOrdMap[finalSortedValues[ord]] = ord; } final SortedDocValues docValues = new BufferedSortedDocValues(hash, valueCount, finalOrds, finalSortedValues, finalOrdMap, docsWithField.iterator()); return Sorter.getDocComparator(maxDoc, sortField, () -> docValues, () -> null); }
throw new IllegalArgumentException("unhandled SortField.getType()=" + sortField.getType());
for (int i = 0; i < numSortFields; ++i) { SortField sortField = indexSort.getSort()[i]; SortField.Type sortType = sortField.getType(); output.writeString(sortField.getField()); int sortTypeID; switch (sortField.getType()) { case STRING: sortTypeID = 0; throw new IllegalStateException("Unexpected sort type: " + sortField.getType()); break; default: throw new IllegalStateException("Unexpected sort type: " + sortField.getType());
public static SortField.Type getSortFieldType(SortField sortField) { if (sortField instanceof SortedSetSortField) { return SortField.Type.STRING; } else if (sortField instanceof SortedNumericSortField) { return ((SortedNumericSortField) sortField).getNumericType(); } else { return sortField.getType(); } } }
switch (field.getType()) { case DOC: type = "doc";
public static Optional<SortAndFormats> buildSort(List<SortBuilder<?>> sortBuilders, QueryShardContext context) throws IOException { List<SortField> sortFields = new ArrayList<>(sortBuilders.size()); List<DocValueFormat> sortFormats = new ArrayList<>(sortBuilders.size()); for (SortBuilder<?> builder : sortBuilders) { SortFieldAndFormat sf = builder.build(context); sortFields.add(sf.field); sortFormats.add(sf.format); } if (!sortFields.isEmpty()) { // optimize if we just sort on score non reversed, we don't really // need sorting boolean sort; if (sortFields.size() > 1) { sort = true; } else { SortField sortField = sortFields.get(0); if (sortField.getType() == SortField.Type.SCORE && !sortField.getReverse()) { sort = false; } else { sort = true; } } if (sort) { return Optional.of(new SortAndFormats( new Sort(sortFields.toArray(new SortField[sortFields.size()])), sortFormats.toArray(new DocValueFormat[sortFormats.size()]))); } } return Optional.empty(); }
/** * Returns the inner {@link SortField.Type} expected for this sort field. */ static SortField.Type extractSortType(SortField sortField) { if (sortField.getComparatorSource() instanceof IndexFieldData.XFieldComparatorSource) { return ((IndexFieldData.XFieldComparatorSource) sortField.getComparatorSource()).reducedType(); } else if (sortField instanceof SortedSetSortField) { return SortField.Type.STRING; } else if (sortField instanceof SortedNumericSortField) { return ((SortedNumericSortField) sortField).getNumericType(); } else if ("LatLonPointSortField".equals(sortField.getClass().getSimpleName())) { // for geo distance sorting return SortField.Type.DOUBLE; } else { return sortField.getType(); } }
for (int index = 0; index < sort.getSort().length; index++) { SortField sortField = sort.getSort()[index]; if (sortField.getType() == SCORE) { scorePos = index; break;
sortFields = fieldDocs.fields; if (fieldDocs instanceof CollapseTopFieldDocs) { isSortedByField = (fieldDocs.fields.length == 1 && fieldDocs.fields[0].getType() == SortField.Type.SCORE) == false; CollapseTopFieldDocs collapseTopFieldDocs = (CollapseTopFieldDocs) fieldDocs; collapseField = collapseTopFieldDocs.field;
SortField[] sortFields = sortedTopDocs.sortFields; for (int i = 0; i < sortFields.length; i++) { if (sortFields[i].getType() == SortField.Type.SCORE) { sortScoreIndex = i;
writeMissingValue(out, comparatorSource.missingValue(sortField.getReverse())); } else { writeSortType(out, sortField.getType()); writeMissingValue(out, sortField.getMissingValue());
/** Returns the native sort type for {@link SortedSetSortField} and {@link SortedNumericSortField}, * {@link SortField#getType()} otherwise */ static SortField.Type getSortFieldType(SortField sortField) { if (sortField instanceof SortedSetSortField) { return SortField.Type.STRING; } else if (sortField instanceof SortedNumericSortField) { return ((SortedNumericSortField) sortField).getNumericType(); } else { return sortField.getType(); } }
private void validateNumericEncodingType(SortField sortField, NumericEncodingType sortEncodingType, NumericEncodingType indexEncodingType) { if ( sortEncodingType != indexEncodingType ) { throw LOG.sortTypeDoesNotMatchFieldType( String.valueOf( sortField.getType() ), String.valueOf( indexEncodingType ), sortField.getField() ); } }
private void validateNumericEncodingType(SortField sortField, NumericEncodingType sortEncodingType, NumericEncodingType indexEncodingType) { if ( sortEncodingType != indexEncodingType ) { throw LOG.sortTypeDoesNotMatchFieldType( String.valueOf( sortField.getType() ), String.valueOf( indexEncodingType ), sortField.getField() ); } }
private void assertType(SortField sortField, FieldType actual, FieldType expected) { if ( actual != expected ) { throw LOG.sortTypeDoesNotMatchFieldType( String.valueOf( sortField.getType() ), String.valueOf( actual ), sortField.getField() ); } }
@Test public void testBuildSortForNullEncoding() { LuceneQueryParsingResult<Class<?>> result = parseAndTransform("select e from org.infinispan.query.dsl.embedded.impl.model.Employee e order by e.code DESC"); Sort sort = result.getSort(); assertThat(sort).isNotNull(); assertThat(sort.getSort().length).isEqualTo(1); assertThat(sort.getSort()[0].getField()).isEqualTo("code"); assertThat(sort.getSort()[0].getType()).isEqualTo(SortField.Type.LONG); }