use of org.opensearch.search.SearchSortValuesAndFormats in project OpenSearch by opensearch-project.
the class BottomSortValuesCollector method consumeTopDocs.
synchronized void consumeTopDocs(TopFieldDocs topDocs, DocValueFormat[] sortValuesFormat) {
totalHits += topDocs.totalHits.value;
if (validateShardSortFields(topDocs.fields) == false) {
return;
}
FieldDoc shardBottomDoc = extractBottom(topDocs);
if (shardBottomDoc == null) {
return;
}
if (bottomSortValues == null || compareValues(shardBottomDoc.fields, bottomSortValues.getRawSortValues()) < 0) {
bottomSortValues = new SearchSortValuesAndFormats(shardBottomDoc.fields, sortValuesFormat);
}
}
use of org.opensearch.search.SearchSortValuesAndFormats in project OpenSearch by opensearch-project.
the class FieldSortBuilderTests method testIsBottomSortShardDisjoint.
public void testIsBottomSortShardDisjoint() throws Exception {
try (Directory dir = newDirectory()) {
int numDocs = randomIntBetween(5, 10);
long maxValue = -1;
long minValue = Integer.MAX_VALUE;
try (RandomIndexWriter writer = new RandomIndexWriter(random(), dir, new KeywordAnalyzer())) {
FieldSortBuilder fieldSort = SortBuilders.fieldSort("custom-date");
try (DirectoryReader reader = writer.getReader()) {
QueryShardContext context = createMockShardContext(new IndexSearcher(reader));
assertTrue(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { 0L }, new DocValueFormat[] { DocValueFormat.RAW })));
}
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
long value = randomLongBetween(1, Integer.MAX_VALUE);
doc.add(new LongPoint("custom-date", value));
doc.add(new SortedNumericDocValuesField("custom-date", value));
writer.addDocument(doc);
maxValue = Math.max(maxValue, value);
minValue = Math.min(minValue, value);
}
try (DirectoryReader reader = writer.getReader()) {
QueryShardContext context = createMockShardContext(new IndexSearcher(reader));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, null));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
assertTrue(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { minValue - 1 }, new DocValueFormat[] { DocValueFormat.RAW })));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { minValue + 1 }, new DocValueFormat[] { DocValueFormat.RAW })));
fieldSort.order(SortOrder.DESC);
assertTrue(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { maxValue + 1 }, new DocValueFormat[] { DocValueFormat.RAW })));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { maxValue }, new DocValueFormat[] { DocValueFormat.RAW })));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { minValue }, new DocValueFormat[] { DocValueFormat.RAW })));
fieldSort.setNestedSort(new NestedSortBuilder("empty"));
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { minValue - 1 }, new DocValueFormat[] { DocValueFormat.RAW })));
fieldSort.setNestedSort(null);
fieldSort.missing("100");
assertFalse(fieldSort.isBottomSortShardDisjoint(context, new SearchSortValuesAndFormats(new Object[] { maxValue + 1 }, new DocValueFormat[] { DocValueFormat.RAW })));
}
}
}
}
Aggregations