Skip to content

Commit 8ac4ebc

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent c165867 commit 8ac4ebc

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapper.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,10 @@ public SparseVectorFieldMapper build(MapperBuilderContext context) {
143143
}
144144

145145
private IndexOptions getDefaultIndexOptions(IndexVersion indexVersion) {
146-
return (
147-
indexVersion.onOrAfter(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION) ||
148-
indexVersion.between(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0)
149-
)
150-
? IndexOptions.DEFAULT_PRUNING_INDEX_OPTIONS
151-
: null;
146+
return (indexVersion.onOrAfter(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION)
147+
|| indexVersion.between(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0))
148+
? IndexOptions.DEFAULT_PRUNING_INDEX_OPTIONS
149+
: null;
152150
}
153151

154152
private boolean indexOptionsSerializerCheck(boolean includeDefaults, boolean isConfigured, IndexOptions value) {
@@ -308,11 +306,7 @@ public IndexVersion getIndexVersionCreated() {
308306
}
309307
}
310308

311-
private SparseVectorFieldMapper(
312-
String simpleName,
313-
MappedFieldType mappedFieldType,
314-
BuilderParams builderParams
315-
) {
309+
private SparseVectorFieldMapper(String simpleName, MappedFieldType mappedFieldType, BuilderParams builderParams) {
316310
super(simpleName, mappedFieldType, builderParams);
317311
}
318312

@@ -412,13 +406,9 @@ protected String contentType() {
412406

413407
private static boolean indexVersionSupportsDefaultPruningConfig(IndexVersion indexVersion) {
414408
// default pruning for 9.1.0+ or 8.19.0+ is true for this index
415-
return (
416-
indexVersion != null &&
417-
(
418-
indexVersion.onOrAfter(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION) ||
419-
indexVersion.between(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0)
420-
)
421-
);
409+
return (indexVersion != null
410+
&& (indexVersion.onOrAfter(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION)
411+
|| indexVersion.between(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0)));
422412
}
423413

424414
private static class SparseVectorValueFetcher implements ValueFetcher {
@@ -558,8 +548,8 @@ public static class IndexOptions implements ToXContent {
558548

559549
public static boolean isDefaultOptions(IndexOptions indexOptions, IndexVersion indexVersion) {
560550
IndexOptions defaultIndexOptions = indexVersionSupportsDefaultPruningConfig(indexVersion)
561-
? DEFAULT_PRUNING_INDEX_OPTIONS
562-
: null;
551+
? DEFAULT_PRUNING_INDEX_OPTIONS
552+
: null;
563553

564554
return Objects.equals(indexOptions, defaultIndexOptions);
565555
}

server/src/test/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapperTests.java

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import org.elasticsearch.common.Strings;
2424
import org.elasticsearch.common.compress.CompressedXContent;
2525
import org.elasticsearch.core.CheckedConsumer;
26-
import org.elasticsearch.core.CheckedRunnable;
27-
import org.elasticsearch.core.CheckedSupplier;
2826
import org.elasticsearch.core.Nullable;
2927
import org.elasticsearch.index.IndexVersion;
3028
import org.elasticsearch.index.IndexVersions;
@@ -49,11 +47,9 @@
4947
import java.io.IOException;
5048
import java.util.Arrays;
5149
import java.util.Collection;
52-
import java.util.Collections;
5350
import java.util.LinkedHashMap;
5451
import java.util.List;
5552
import java.util.Map;
56-
import java.util.Optional;
5753

5854
import static org.elasticsearch.index.IndexVersions.SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT;
5955
import static org.elasticsearch.index.IndexVersions.UPGRADE_TO_LUCENE_10_0_0;
@@ -92,7 +88,7 @@ protected void minimalFieldMappingPreviousIndexVersion(XContentBuilder b) throws
9288
b.startObject("meta");
9389
b.endObject();
9490

95-
b.field("index_options", (Object)null);
91+
b.field("index_options", (Object) null);
9692
}
9793

9894
protected void minimalMappingWithExplicitDefaults(XContentBuilder b) throws IOException {
@@ -230,7 +226,8 @@ public void testDefaults() throws Exception {
230226
assertTrue(freq1 < freq2);
231227
}
232228

233-
private void buildDocForSparseVectorFieldMapping(XContentBuilder b, CheckedConsumer<XContentBuilder, IOException> supplier) throws IOException {
229+
private void buildDocForSparseVectorFieldMapping(XContentBuilder b, CheckedConsumer<XContentBuilder, IOException> supplier)
230+
throws IOException {
234231
b.startObject("_doc");
235232
{
236233
b.startArray("dynamic_date_formats");
@@ -740,12 +737,7 @@ public void testTypeQueryFinalizationWithIndexExplicit() throws Exception {
740737
MapperService mapperService = createMapperService(version, fieldMapping(this::minimalMapping));
741738

742739
// query should be pruned via explicit index options
743-
performTypeQueryFinalizationTest(
744-
mapperService,
745-
null,
746-
null,
747-
true
748-
);
740+
performTypeQueryFinalizationTest(mapperService, null, null, true);
749741
}
750742

751743
public void testTypeQueryFinalizationWithIndexExplicitDoNotPrune() throws Exception {
@@ -761,25 +753,15 @@ public void testTypeQueryFinalizationQueryOverridesPruning() throws Exception {
761753
MapperService mapperService = createMapperService(version, fieldMapping(this::mappingWithIndexOptionsPruneFalse));
762754

763755
// query should still be pruned due to query builder setting it
764-
performTypeQueryFinalizationTest(
765-
mapperService,
766-
true,
767-
new TokenPruningConfig(),
768-
true
769-
);
756+
performTypeQueryFinalizationTest(mapperService, true, new TokenPruningConfig(), true);
770757
}
771758

772759
public void testTypeQueryFinalizationQueryOverridesPruningOff() throws Exception {
773760
IndexVersion version = IndexVersion.current();
774761
MapperService mapperService = createMapperService(version, fieldMapping(this::mappingWithIndexOptionsPruneFalse));
775762

776763
// query should not pruned due to query builder setting it
777-
performTypeQueryFinalizationTest(
778-
mapperService,
779-
false,
780-
null,
781-
false
782-
);
764+
performTypeQueryFinalizationTest(mapperService, false, null, false);
783765
}
784766

785767
private void performTypeQueryFinalizationTest(
@@ -789,8 +771,9 @@ private void performTypeQueryFinalizationTest(
789771
boolean queryShouldBePruned
790772
) throws IOException {
791773
withSearchExecutionContext(mapperService, (context) -> {
792-
SparseVectorFieldMapper.SparseVectorFieldType ft = (SparseVectorFieldMapper.SparseVectorFieldType) mapperService
793-
.fieldType("field");
774+
SparseVectorFieldMapper.SparseVectorFieldType ft = (SparseVectorFieldMapper.SparseVectorFieldType) mapperService.fieldType(
775+
"field"
776+
);
794777
Query finalizedQuery = ft.finalizeSparseVectorQuery(context, "field", QUERY_VECTORS, queryPrune, queryTokenPruningConfig);
795778

796779
if (queryShouldBePruned) {
@@ -851,20 +834,13 @@ private void runTestTypeQueryFinalization(
851834
// we should _not_ prune if any of the following:
852835
// - the query explicitly overrides the options and `prune` is set to false
853836
// - the query does not override the pruning options and:
854-
// - either we are using a previous index version
855-
// - or the index_options explicitly sets `prune` to false
856-
boolean resultShouldNotBePruned = (
857-
(queryOverridesPruning && queryOverrideExplicitFalse) ||
858-
(queryOverridesPruning == false && (usePreviousIndex || explicitIndexOptionsDoNotPrune))
859-
);
837+
// - either we are using a previous index version
838+
// - or the index_options explicitly sets `prune` to false
839+
boolean resultShouldNotBePruned = ((queryOverridesPruning && queryOverrideExplicitFalse)
840+
|| (queryOverridesPruning == false && (usePreviousIndex || explicitIndexOptionsDoNotPrune)));
860841

861842
try {
862-
performTypeQueryFinalizationTest(
863-
mapperService,
864-
shouldQueryPrune,
865-
queryPruningConfig,
866-
resultShouldNotBePruned == false
867-
);
843+
performTypeQueryFinalizationTest(mapperService, shouldQueryPrune, queryPruningConfig, resultShouldNotBePruned == false);
868844
} catch (AssertionError e) {
869845
String message = "performTypeQueryFinalizationTest failed using parameters: "
870846
+ "usePreviousIndex: "
@@ -884,16 +860,12 @@ private void runTestTypeQueryFinalization(
884860

885861
private IndexVersion getIndexVersionForTest(boolean usePreviousIndex) {
886862
return usePreviousIndex
887-
? IndexVersionUtils.randomVersionBetween(
888-
random(),
889-
UPGRADE_TO_LUCENE_10_0_0,
890-
IndexVersionUtils.getPreviousVersion(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT)
891-
)
892-
: IndexVersionUtils.randomVersionBetween(
893-
random(),
894-
SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT,
895-
IndexVersion.current()
896-
);
863+
? IndexVersionUtils.randomVersionBetween(
864+
random(),
865+
UPGRADE_TO_LUCENE_10_0_0,
866+
IndexVersionUtils.getPreviousVersion(SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT)
867+
)
868+
: IndexVersionUtils.randomVersionBetween(random(), SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT, IndexVersion.current());
897869
}
898870

899871
private SparseVectorFieldMapper.IndexOptions getIndexOptionsQueryFinalization(

0 commit comments

Comments
 (0)