Skip to content

Commit dce64b2

Browse files
committed
Add BWCLucene86Codec
1 parent 33f3f36 commit dce64b2

File tree

2 files changed

+161
-1
lines changed

2 files changed

+161
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.lucene.bwc.codecs;
99

10+
import org.apache.lucene.backward_codecs.lucene86.Lucene86Codec;
1011
import org.apache.lucene.backward_codecs.lucene87.Lucene87Codec;
1112
import org.apache.lucene.codecs.Codec;
1213
import org.apache.lucene.codecs.FieldInfosFormat;
@@ -27,6 +28,7 @@
2728
import org.apache.lucene.index.Terms;
2829
import org.apache.lucene.store.Directory;
2930
import org.apache.lucene.store.IOContext;
31+
import org.elasticsearch.xpack.lucene.bwc.codecs.lucene86.BWCLucene86Codec;
3032
import org.elasticsearch.xpack.lucene.bwc.codecs.lucene87.BWCLucene87Codec;
3133

3234
import java.io.IOException;
@@ -122,7 +124,12 @@ private static FieldInfos filterFields(FieldInfos fieldInfos) {
122124
public static SegmentInfo wrap(SegmentInfo segmentInfo) {
123125
// special handling for Lucene87Codec (which is currently bundled with Lucene)
124126
// Use BWCLucene87Codec instead as that one extends BWCCodec (similar to all other older codecs)
125-
final Codec codec = segmentInfo.getCodec() instanceof Lucene87Codec ? new BWCLucene87Codec() : segmentInfo.getCodec();
127+
Codec codec = segmentInfo.getCodec();
128+
if (codec instanceof Lucene86Codec) {
129+
codec = new BWCLucene86Codec();
130+
} else if (codec instanceof Lucene87Codec) {
131+
codec = new BWCLucene87Codec();
132+
}
126133
final SegmentInfo segmentInfo1 = new SegmentInfo(
127134
segmentInfo.dir,
128135
// Use Version.LATEST instead of original version, otherwise SegmentCommitInfo will bark when processing (N-1 limitation)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.lucene.bwc.codecs.lucene86;
9+
10+
import org.apache.lucene.backward_codecs.lucene50.Lucene50CompoundFormat;
11+
import org.apache.lucene.backward_codecs.lucene50.Lucene50LiveDocsFormat;
12+
import org.apache.lucene.backward_codecs.lucene50.Lucene50StoredFieldsFormat;
13+
import org.apache.lucene.backward_codecs.lucene50.Lucene50TermVectorsFormat;
14+
import org.apache.lucene.backward_codecs.lucene60.Lucene60FieldInfosFormat;
15+
import org.apache.lucene.backward_codecs.lucene80.Lucene80NormsFormat;
16+
import org.apache.lucene.backward_codecs.lucene84.Lucene84PostingsFormat;
17+
import org.apache.lucene.backward_codecs.lucene86.Lucene86PointsFormat;
18+
import org.apache.lucene.backward_codecs.lucene86.Lucene86SegmentInfoFormat;
19+
import org.apache.lucene.codecs.CompoundFormat;
20+
import org.apache.lucene.codecs.DocValuesFormat;
21+
import org.apache.lucene.codecs.FieldInfosFormat;
22+
import org.apache.lucene.codecs.KnnVectorsFormat;
23+
import org.apache.lucene.codecs.LiveDocsFormat;
24+
import org.apache.lucene.codecs.NormsFormat;
25+
import org.apache.lucene.codecs.PointsFormat;
26+
import org.apache.lucene.codecs.PostingsFormat;
27+
import org.apache.lucene.codecs.SegmentInfoFormat;
28+
import org.apache.lucene.codecs.StoredFieldsFormat;
29+
import org.apache.lucene.codecs.TermVectorsFormat;
30+
import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;
31+
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
32+
import org.elasticsearch.xpack.lucene.bwc.codecs.BWCCodec;
33+
34+
import java.util.Objects;
35+
36+
public class BWCLucene86Codec extends BWCCodec {
37+
38+
private final TermVectorsFormat vectorsFormat = new Lucene50TermVectorsFormat();
39+
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
40+
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene86SegmentInfoFormat());
41+
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
42+
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
43+
private final PointsFormat pointsFormat = new Lucene86PointsFormat();
44+
private final PostingsFormat defaultFormat;
45+
46+
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
47+
@Override
48+
public PostingsFormat getPostingsFormatForField(String field) {
49+
return BWCLucene86Codec.this.getPostingsFormatForField(field);
50+
}
51+
};
52+
53+
private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {
54+
@Override
55+
public DocValuesFormat getDocValuesFormatForField(String field) {
56+
return BWCLucene86Codec.this.getDocValuesFormatForField(field);
57+
}
58+
};
59+
60+
private final StoredFieldsFormat storedFieldsFormat;
61+
62+
/** Instantiates a new codec. */
63+
public BWCLucene86Codec() {
64+
super("BWCLucene87Codec");
65+
this.storedFieldsFormat = new Lucene50StoredFieldsFormat(Objects.requireNonNull(Lucene50StoredFieldsFormat.Mode.BEST_SPEED));
66+
this.defaultFormat = new Lucene84PostingsFormat();
67+
}
68+
69+
@Override
70+
public StoredFieldsFormat storedFieldsFormat() {
71+
return storedFieldsFormat;
72+
}
73+
74+
@Override
75+
public TermVectorsFormat termVectorsFormat() {
76+
return vectorsFormat;
77+
}
78+
79+
@Override
80+
public PostingsFormat postingsFormat() {
81+
return postingsFormat;
82+
}
83+
84+
@Override
85+
public final FieldInfosFormat fieldInfosFormat() {
86+
return fieldInfosFormat;
87+
}
88+
89+
@Override
90+
public SegmentInfoFormat segmentInfoFormat() {
91+
return segmentInfosFormat;
92+
}
93+
94+
@Override
95+
public final LiveDocsFormat liveDocsFormat() {
96+
return liveDocsFormat;
97+
}
98+
99+
@Override
100+
public CompoundFormat compoundFormat() {
101+
return compoundFormat;
102+
}
103+
104+
@Override
105+
public PointsFormat pointsFormat() {
106+
return pointsFormat;
107+
}
108+
109+
@Override
110+
public final KnnVectorsFormat knnVectorsFormat() {
111+
return KnnVectorsFormat.EMPTY;
112+
}
113+
114+
/**
115+
* Returns the postings format that should be used for writing new segments of <code>field</code>.
116+
*
117+
* <p>The default implementation always returns "Lucene84".
118+
*
119+
* <p><b>WARNING:</b> if you subclass, you are responsible for index backwards compatibility:
120+
* future version of Lucene are only guaranteed to be able to read the default implementation.
121+
*/
122+
public PostingsFormat getPostingsFormatForField(String field) {
123+
return defaultFormat;
124+
}
125+
126+
/**
127+
* Returns the docvalues format that should be used for writing new segments of <code>field</code>
128+
* .
129+
*
130+
* <p>The default implementation always returns "Lucene80".
131+
*
132+
* <p><b>WARNING:</b> if you subclass, you are responsible for index backwards compatibility:
133+
* future version of Lucene are only guaranteed to be able to read the default implementation.
134+
*/
135+
public DocValuesFormat getDocValuesFormatForField(String field) {
136+
return defaultDVFormat;
137+
}
138+
139+
@Override
140+
public final DocValuesFormat docValuesFormat() {
141+
return docValuesFormat;
142+
}
143+
144+
private final DocValuesFormat defaultDVFormat = DocValuesFormat.forName("Lucene80");
145+
146+
private final NormsFormat normsFormat = new Lucene80NormsFormat();
147+
148+
@Override
149+
public NormsFormat normsFormat() {
150+
return normsFormat;
151+
}
152+
153+
}

0 commit comments

Comments
 (0)