Skip to content

Commit 9c9dc66

Browse files
committed
Update after review
1 parent bb93eac commit 9c9dc66

File tree

9 files changed

+95
-170
lines changed

9 files changed

+95
-170
lines changed

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/BWCCodec.java

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,41 @@
4343
*/
4444
public abstract class BWCCodec extends Codec {
4545

46-
protected FieldInfosFormat fieldInfosFormat;
47-
protected SegmentInfoFormat segmentInfosFormat;
46+
private final FieldInfosFormat fieldInfosFormat;
47+
private final SegmentInfoFormat segmentInfosFormat;
4848

4949
protected BWCCodec(String name) {
5050
super(name);
51-
this.fieldInfosFormat = wrappedFieldInfosFormat();
52-
this.segmentInfosFormat = wrappedSegmentInfoFormat();
51+
52+
this.fieldInfosFormat = new FieldInfosFormat() {
53+
final FieldInfosFormat wrappedFormat = originalFieldInfosFormat();
54+
55+
@Override
56+
public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext)
57+
throws IOException {
58+
return filterFields(wrappedFormat.read(directory, segmentInfo, segmentSuffix, iocontext));
59+
}
60+
61+
@Override
62+
public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context)
63+
throws IOException {
64+
wrappedFormat.write(directory, segmentInfo, segmentSuffix, infos, context);
65+
}
66+
};
67+
68+
this.segmentInfosFormat = new SegmentInfoFormat() {
69+
final SegmentInfoFormat wrappedFormat = originalSegmentInfoFormat();
70+
71+
@Override
72+
public SegmentInfo read(Directory directory, String segmentName, byte[] segmentID, IOContext context) throws IOException {
73+
return wrap(wrappedFormat.read(directory, segmentName, segmentID, context));
74+
}
75+
76+
@Override
77+
public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {
78+
wrappedFormat.write(dir, info, ioContext);
79+
}
80+
};
5381
}
5482

5583
protected final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
@@ -59,6 +87,16 @@ public PostingsFormat getPostingsFormatForField(String field) {
5987
}
6088
};
6189

90+
@Override
91+
public final FieldInfosFormat fieldInfosFormat() {
92+
return fieldInfosFormat;
93+
}
94+
95+
@Override
96+
public SegmentInfoFormat segmentInfoFormat() {
97+
return segmentInfosFormat;
98+
}
99+
62100
@Override
63101
public final NormsFormat normsFormat() {
64102
throw new UnsupportedOperationException();
@@ -74,43 +112,9 @@ public final KnnVectorsFormat knnVectorsFormat() {
74112
throw new UnsupportedOperationException();
75113
}
76114

77-
protected abstract SegmentInfoFormat setSegmentInfoFormat();
78-
79-
protected final SegmentInfoFormat wrappedSegmentInfoFormat() {
80-
return new SegmentInfoFormat() {
81-
final SegmentInfoFormat wrappedFormat = setSegmentInfoFormat();
82-
83-
@Override
84-
public SegmentInfo read(Directory directory, String segmentName, byte[] segmentID, IOContext context) throws IOException {
85-
return wrap(wrappedFormat.read(directory, segmentName, segmentID, context));
86-
}
87-
88-
@Override
89-
public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {
90-
wrappedFormat.write(dir, info, ioContext);
91-
}
92-
};
93-
}
94-
95-
protected abstract FieldInfosFormat setFieldInfosFormat();
96-
97-
protected final FieldInfosFormat wrappedFieldInfosFormat() {
98-
return new FieldInfosFormat() {
99-
final FieldInfosFormat wrappedFormat = setFieldInfosFormat();
100-
101-
@Override
102-
public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext)
103-
throws IOException {
104-
return filterFields(wrappedFormat.read(directory, segmentInfo, segmentSuffix, iocontext));
105-
}
115+
protected abstract SegmentInfoFormat originalSegmentInfoFormat();
106116

107-
@Override
108-
public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context)
109-
throws IOException {
110-
wrappedFormat.write(directory, segmentInfo, segmentSuffix, infos, context);
111-
}
112-
};
113-
}
117+
protected abstract FieldInfosFormat originalFieldInfosFormat();
114118

115119
// mark all fields as no term vectors, no norms, no payloads, and no vectors.
116120
private static FieldInfos filterFields(FieldInfos fieldInfos) {

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene60/Lucene60Codec.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@
4848
@Deprecated
4949
public class Lucene60Codec extends BWCCodec {
5050

51-
@Override
52-
protected FieldInfosFormat setFieldInfosFormat() {
53-
return new Lucene60FieldInfosFormat();
54-
}
55-
56-
@Override
57-
protected SegmentInfoFormat setSegmentInfoFormat() {
58-
return new Lucene50SegmentInfoFormat();
59-
}
60-
6151
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
6252
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
6353
private final StoredFieldsFormat storedFieldsFormat;
@@ -98,18 +88,18 @@ public Lucene60Codec(Lucene50StoredFieldsFormat.Mode mode) {
9888
}
9989

10090
@Override
101-
public final StoredFieldsFormat storedFieldsFormat() {
102-
return storedFieldsFormat;
91+
protected FieldInfosFormat originalFieldInfosFormat() {
92+
return new Lucene60FieldInfosFormat();
10393
}
10494

10595
@Override
106-
public final FieldInfosFormat fieldInfosFormat() {
107-
return fieldInfosFormat;
96+
protected SegmentInfoFormat originalSegmentInfoFormat() {
97+
return new Lucene50SegmentInfoFormat();
10898
}
10999

110100
@Override
111-
public SegmentInfoFormat segmentInfoFormat() {
112-
return segmentInfosFormat;
101+
public final StoredFieldsFormat storedFieldsFormat() {
102+
return storedFieldsFormat;
113103
}
114104

115105
@Override

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene62/Lucene62Codec.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@
4848
@Deprecated
4949
public class Lucene62Codec extends BWCCodec {
5050

51-
@Override
52-
protected FieldInfosFormat setFieldInfosFormat() {
53-
return new Lucene60FieldInfosFormat();
54-
}
55-
56-
@Override
57-
protected SegmentInfoFormat setSegmentInfoFormat() {
58-
return new Lucene62SegmentInfoFormat();
59-
}
60-
6151
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
6252
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
6353
private final StoredFieldsFormat storedFieldsFormat;
@@ -89,18 +79,18 @@ public Lucene62Codec(Lucene50StoredFieldsFormat.Mode mode) {
8979
}
9080

9181
@Override
92-
public final StoredFieldsFormat storedFieldsFormat() {
93-
return storedFieldsFormat;
82+
protected FieldInfosFormat originalFieldInfosFormat() {
83+
return new Lucene60FieldInfosFormat();
9484
}
9585

9686
@Override
97-
public final FieldInfosFormat fieldInfosFormat() {
98-
return fieldInfosFormat;
87+
protected SegmentInfoFormat originalSegmentInfoFormat() {
88+
return new Lucene62SegmentInfoFormat();
9989
}
10090

10191
@Override
102-
public SegmentInfoFormat segmentInfoFormat() {
103-
return segmentInfosFormat;
92+
public final StoredFieldsFormat storedFieldsFormat() {
93+
return storedFieldsFormat;
10494
}
10595

10696
@Override

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene70/BWCLucene70Codec.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@
3232
*/
3333
public class BWCLucene70Codec extends BWCCodec {
3434

35-
@Override
36-
protected FieldInfosFormat setFieldInfosFormat() {
37-
return new Lucene60FieldInfosFormat();
38-
}
39-
40-
@Override
41-
protected SegmentInfoFormat setSegmentInfoFormat() {
42-
return new Lucene70SegmentInfoFormat();
43-
}
44-
4535
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
4636
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
4737
private final StoredFieldsFormat storedFieldsFormat;
@@ -66,15 +56,16 @@ protected BWCLucene70Codec(String name) {
6656
}
6757

6858
@Override
69-
public FieldInfosFormat fieldInfosFormat() {
70-
return fieldInfosFormat;
59+
protected FieldInfosFormat originalFieldInfosFormat() {
60+
return new Lucene60FieldInfosFormat();
7161
}
7262

7363
@Override
74-
public SegmentInfoFormat segmentInfoFormat() {
75-
return segmentInfosFormat;
64+
protected SegmentInfoFormat originalSegmentInfoFormat() {
65+
return new Lucene70SegmentInfoFormat();
7666
}
7767

68+
7869
@Override
7970
public StoredFieldsFormat storedFieldsFormat() {
8071
return storedFieldsFormat;

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene80/BWCLucene80Codec.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
*/
3232
public class BWCLucene80Codec extends BWCCodec {
3333

34-
@Override
35-
protected FieldInfosFormat setFieldInfosFormat() {
36-
return new Lucene60FieldInfosFormat();
37-
}
38-
39-
@Override
40-
protected SegmentInfoFormat setSegmentInfoFormat() {
41-
return new Lucene70SegmentInfoFormat();
42-
}
43-
4434
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
4535
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
4636

@@ -67,23 +57,23 @@ public BWCLucene80Codec(String name) {
6757
}
6858

6959
@Override
70-
public final StoredFieldsFormat storedFieldsFormat() {
71-
return storedFieldsFormat;
60+
protected FieldInfosFormat originalFieldInfosFormat() {
61+
return new Lucene60FieldInfosFormat();
7262
}
7363

7464
@Override
75-
public final PostingsFormat postingsFormat() {
76-
return postingsFormat;
65+
protected SegmentInfoFormat originalSegmentInfoFormat() {
66+
return new Lucene70SegmentInfoFormat();
7767
}
7868

7969
@Override
80-
public final FieldInfosFormat fieldInfosFormat() {
81-
return fieldInfosFormat;
70+
public final StoredFieldsFormat storedFieldsFormat() {
71+
return storedFieldsFormat;
8272
}
8373

8474
@Override
85-
public final SegmentInfoFormat segmentInfoFormat() {
86-
return segmentInfosFormat;
75+
public final PostingsFormat postingsFormat() {
76+
return postingsFormat;
8777
}
8878

8979
@Override

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene84/BWCLucene84Codec.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@
3333
*/
3434
public class BWCLucene84Codec extends BWCCodec {
3535

36-
@Override
37-
protected FieldInfosFormat setFieldInfosFormat() {
38-
return new Lucene60FieldInfosFormat();
39-
}
40-
41-
@Override
42-
protected SegmentInfoFormat setSegmentInfoFormat() {
43-
return new Lucene70SegmentInfoFormat();
44-
}
45-
4636
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
4737
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
4838
private final PostingsFormat defaultFormat;
@@ -77,23 +67,23 @@ public BWCLucene84Codec(String name) {
7767
}
7868

7969
@Override
80-
public StoredFieldsFormat storedFieldsFormat() {
81-
return storedFieldsFormat;
70+
protected FieldInfosFormat originalFieldInfosFormat() {
71+
return new Lucene60FieldInfosFormat();
8272
}
8373

8474
@Override
85-
public PostingsFormat postingsFormat() {
86-
return postingsFormat;
75+
protected SegmentInfoFormat originalSegmentInfoFormat() {
76+
return new Lucene70SegmentInfoFormat();
8777
}
8878

8979
@Override
90-
public final FieldInfosFormat fieldInfosFormat() {
91-
return fieldInfosFormat;
80+
public StoredFieldsFormat storedFieldsFormat() {
81+
return storedFieldsFormat;
9282
}
9383

9484
@Override
95-
public SegmentInfoFormat segmentInfoFormat() {
96-
return segmentInfosFormat;
85+
public PostingsFormat postingsFormat() {
86+
return postingsFormat;
9787
}
9888

9989
@Override

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene86/BWCLucene86Codec.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@
3232
*/
3333
public class BWCLucene86Codec extends BWCCodec {
3434

35-
@Override
36-
protected FieldInfosFormat setFieldInfosFormat() {
37-
return new Lucene60FieldInfosFormat();
38-
}
39-
40-
@Override
41-
protected SegmentInfoFormat setSegmentInfoFormat() {
42-
return new Lucene86SegmentInfoFormat();
43-
}
44-
4535
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
4636
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
4737
private final PointsFormat pointsFormat = new Lucene86MetadataOnlyPointsFormat();
@@ -77,23 +67,23 @@ public BWCLucene86Codec(String name) {
7767
}
7868

7969
@Override
80-
public StoredFieldsFormat storedFieldsFormat() {
81-
return storedFieldsFormat;
70+
protected FieldInfosFormat originalFieldInfosFormat() {
71+
return new Lucene60FieldInfosFormat();
8272
}
8373

8474
@Override
85-
public PostingsFormat postingsFormat() {
86-
return postingsFormat;
75+
protected SegmentInfoFormat originalSegmentInfoFormat() {
76+
return new Lucene86SegmentInfoFormat();
8777
}
8878

8979
@Override
90-
public final FieldInfosFormat fieldInfosFormat() {
91-
return fieldInfosFormat;
80+
public StoredFieldsFormat storedFieldsFormat() {
81+
return storedFieldsFormat;
9282
}
9383

9484
@Override
95-
public SegmentInfoFormat segmentInfoFormat() {
96-
return segmentInfosFormat;
85+
public PostingsFormat postingsFormat() {
86+
return postingsFormat;
9787
}
9888

9989
@Override

0 commit comments

Comments
 (0)