/** * Returns a QueryContext with sorting added to it. * * @param key The key to sort on. * @param additionalKeys Any additional keys to sort on. * @return A QueryContext with sorting added to it. */ @Deprecated public QueryContext sort( String key, String... additionalKeys ) { SortField firstSortField = new SortedSetSortField( key, false ); if ( additionalKeys.length == 0 ) { return sort( new Sort( firstSortField ) ); } SortField[] sortFields = new SortField[1 + additionalKeys.length]; sortFields[0] = firstSortField; for ( int i = 0; i < additionalKeys.length; i++ ) { sortFields[1 + i] = new SortedSetSortField( additionalKeys[i], false ); } return sort( new Sort( sortFields ) ); }
private void queryAndSortNodesByStringProperty( Index<Node> index, String stringProperty, IntFunction<String> expectedValueProvider ) { try ( Transaction transaction = graphDb.beginTx() ) { QueryContext queryContext = new QueryContext( stringProperty + ":**" ); queryContext.sort( new Sort( new SortedSetSortField( stringProperty, true ) ) ); IndexHits<Node> nodes = index.query( queryContext ); int nodeIndex = 0; for ( Node node : nodes ) { assertEquals("Nodes should be sorted by string property", expectedValueProvider.apply( nodeIndex++ ), node.getProperty( stringProperty )); } transaction.success(); } }
sortFields[i] = new SortedSetSortField(fieldName, reverse, sortedSetSelector); } else if (sortedNumericSelector != null) { sortFields[i] = new SortedNumericSortField(fieldName, sortType, reverse, sortedNumericSelector);
sortFields[i] = new SortedSetSortField(fieldName, reverse, sortedSetSelector); } else if (sortedNumericSelector != null) { sortFields[i] = new SortedNumericSortField(fieldName, sortType, reverse, sortedNumericSelector);
/** {@inheritDoc} */ @Override public final SortField sortField(String name, boolean reverse) { return new SortedSetSortField(name, reverse); } }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; }
@Override public SortField getSortField(boolean reverse) { return new SortedSetSortField(this.field, reverse, this.selector); }
@Override public SortField getSortField(boolean reverse) { return new SortedSetSortField(this.field, reverse, this.selector); }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, XFieldComparatorSource.Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; } }
@Override public SortField getSortField(boolean reverse) { return new SortedSetSortField(this.field, reverse, this.selector); }
boolean max = in.readBoolean(); boolean reverse = in.readBoolean(); fields[i] = new SortedSetSortField(field, reverse, max ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); if (missingFirst != null) {
private Sort buildSort(ContentRequest req) { // field name String field = req.getParameter("sort"); if (field == null) return null; // reverse order boolean reverse = field.startsWith("-"); if (reverse) field = field.substring(1); // sort type SortField sfield = null; String type = req.getParameter("sort-type", "score"); if ("int".equalsIgnoreCase(type)) sfield = new SortedNumericSortField(field, Type.INT, reverse); else if ("double".equalsIgnoreCase(type)) sfield = new SortedNumericSortField(field, Type.DOUBLE, reverse); else if ("float".equalsIgnoreCase(type)) sfield = new SortedNumericSortField(field, Type.FLOAT, reverse); else if ("long".equalsIgnoreCase(type)) sfield = new SortedNumericSortField(field, Type.LONG, reverse); else if ("document".equalsIgnoreCase(type)) sfield = SortField.FIELD_DOC; else if ("set".equalsIgnoreCase(type)) sfield = new SortedSetSortField(field, reverse); else if ("string".equalsIgnoreCase(type)) sfield = new SortField(field, Type.STRING, reverse); else sfield = SortField.FIELD_SCORE; // build sort field return new Sort(sfield); }
private static int runQuery(IndexReader indexReader, int count, Query q) throws IOException { long start = System.currentTimeMillis(); IndexSearcher searcher = new IndexSearcher(indexReader); Sort sort = new Sort(); sort.setSort(new SortedSetSortField("category", false)); TopFieldCollector collector = TopFieldCollector.create(sort, count, null, true, true, true); searcher.search(q, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; int totalHits = collector.getTotalHits(); @SuppressWarnings("unused") long searchTime = System.currentTimeMillis() - start; start = System.currentTimeMillis(); List<String> ids = new ArrayList<>(); for (ScoreDoc hit : hits) { int docId = hit.doc; Document d = searcher.doc(docId); ids.add(d.get("uid")); } @SuppressWarnings("unused") long fetchTime = System.currentTimeMillis() - start; return totalHits; }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, XFieldComparatorSource.Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; } }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, XFieldComparatorSource.Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; } }
@Override public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, XFieldComparatorSource.Nested nested, boolean reverse) { XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); /** * Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and * returns a custom sort field otherwise. */ if (nested != null || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { return new SortField(getFieldName(), source, reverse); } SortField sortField = new SortedSetSortField(fieldName, reverse, sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); sortField.setMissingValue(source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST); return sortField; } }
boolean max = in.readBoolean(); boolean reverse = in.readBoolean(); fields[i] = new SortedSetSortField(field, reverse, max ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN); if (missingFirst != null) {