use of org.apache.lucene.search.SortedNumericSortField in project lucene-solr by apache.
the class TestIndexSorting method testMultiValuedNumericAlreadySorted.
public void testMultiValuedNumericAlreadySorted() throws Exception {
assertNeedsIndexSortMerge(new SortedNumericSortField("foo", SortField.Type.INT), (doc) -> {
doc.add(new SortedNumericDocValuesField("foo", Integer.MIN_VALUE));
int num = random().nextInt(5);
for (int j = 0; j < num; j++) {
doc.add(new SortedNumericDocValuesField("foo", random().nextInt()));
}
}, (doc) -> {
int num = random().nextInt(5);
for (int j = 0; j < num; j++) {
doc.add(new SortedNumericDocValuesField("foo", random().nextInt()));
}
});
}
use of org.apache.lucene.search.SortedNumericSortField in project querydsl by querydsl.
the class LuceneSerializer method toSort.
public Sort toSort(List<? extends OrderSpecifier<?>> orderBys) {
List<SortField> sorts = new ArrayList<SortField>(orderBys.size());
for (OrderSpecifier<?> order : orderBys) {
if (!(order.getTarget() instanceof Path<?>)) {
throw new IllegalArgumentException("argument was not of type Path.");
}
Class<?> type = order.getTarget().getType();
boolean reverse = !order.isAscending();
Path<?> path = getPath(order.getTarget());
if (Number.class.isAssignableFrom(type)) {
sorts.add(new SortedNumericSortField(toField(path), sortFields.get(type), reverse));
} else {
sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse));
}
}
Sort sort = new Sort();
sort.setSort(sorts.toArray(new SortField[0]));
return sort;
}
use of org.apache.lucene.search.SortedNumericSortField in project crate by crate.
the class LuceneOrderedDocCollectorTest method nextPageQuery.
private Long[] nextPageQuery(IndexReader reader, FieldDoc lastCollected, boolean reverseFlag, boolean nullFirst) throws IOException {
OrderBy orderBy = new OrderBy(List.of(REFERENCE), new boolean[] { reverseFlag }, new boolean[] { nullFirst });
SortField sortField = new SortedNumericSortField("value", SortField.Type.LONG, reverseFlag);
Long missingValue = (Long) NullSentinelValues.nullSentinelForScoreDoc(orderBy, 0);
sortField.setMissingValue(missingValue);
Sort sort = new Sort(sortField);
OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType);
Query nextPageQuery = queryForSearchAfter.apply(lastCollected);
TopFieldDocs result = search(reader, nextPageQuery, sort);
Long[] results = new Long[result.scoreDocs.length];
for (int i = 0; i < result.scoreDocs.length; i++) {
Long value = (Long) ((FieldDoc) result.scoreDocs[i]).fields[0];
results[i] = value.equals(missingValue) ? null : value;
}
return results;
}
Aggregations