Skip to content

Commit 95ba9c4

Browse files
committed
WIP
1 parent d26a772 commit 95ba9c4

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed

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

Lines changed: 5 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.lucene87.Lucene87Codec;
1011
import org.apache.lucene.codecs.Codec;
1112
import org.apache.lucene.codecs.FieldInfosFormat;
1213
import org.apache.lucene.codecs.FieldsConsumer;
@@ -26,6 +27,7 @@
2627
import org.apache.lucene.index.Terms;
2728
import org.apache.lucene.store.Directory;
2829
import org.apache.lucene.store.IOContext;
30+
import org.elasticsearch.xpack.lucene.bwc.codecs.lucene87.BWCLucene87Codec;
2931

3032
import java.io.IOException;
3133
import java.util.ArrayList;
@@ -118,7 +120,9 @@ private static FieldInfos filterFields(FieldInfos fieldInfos) {
118120
}
119121

120122
public static SegmentInfo wrap(SegmentInfo segmentInfo) {
121-
final Codec codec = segmentInfo.getCodec();
123+
// special handling for Lucene87Codec (which is currently bundled with Lucene)
124+
// 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();
122126
final SegmentInfo segmentInfo1 = new SegmentInfo(
123127
segmentInfo.dir,
124128
// 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.lucene87;
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.Lucene50TermVectorsFormat;
13+
import org.apache.lucene.backward_codecs.lucene60.Lucene60FieldInfosFormat;
14+
import org.apache.lucene.backward_codecs.lucene80.Lucene80DocValuesFormat;
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.backward_codecs.lucene87.Lucene87StoredFieldsFormat;
20+
import org.apache.lucene.codecs.CompoundFormat;
21+
import org.apache.lucene.codecs.DocValuesFormat;
22+
import org.apache.lucene.codecs.FieldInfosFormat;
23+
import org.apache.lucene.codecs.KnnVectorsFormat;
24+
import org.apache.lucene.codecs.LiveDocsFormat;
25+
import org.apache.lucene.codecs.NormsFormat;
26+
import org.apache.lucene.codecs.PointsFormat;
27+
import org.apache.lucene.codecs.PostingsFormat;
28+
import org.apache.lucene.codecs.SegmentInfoFormat;
29+
import org.apache.lucene.codecs.StoredFieldsFormat;
30+
import org.apache.lucene.codecs.TermVectorsFormat;
31+
import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;
32+
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
33+
import org.elasticsearch.xpack.lucene.bwc.codecs.BWCCodec;
34+
35+
public class BWCLucene87Codec extends BWCCodec {
36+
37+
private final TermVectorsFormat vectorsFormat = new Lucene50TermVectorsFormat();
38+
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
39+
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene86SegmentInfoFormat());
40+
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
41+
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
42+
private final PointsFormat pointsFormat = new Lucene86PointsFormat();
43+
private final PostingsFormat defaultFormat;
44+
45+
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
46+
@Override
47+
public PostingsFormat getPostingsFormatForField(String field) {
48+
return BWCLucene87Codec.this.getPostingsFormatForField(field);
49+
}
50+
};
51+
52+
private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {
53+
@Override
54+
public DocValuesFormat getDocValuesFormatForField(String field) {
55+
return BWCLucene87Codec.this.getDocValuesFormatForField(field);
56+
}
57+
};
58+
59+
private final StoredFieldsFormat storedFieldsFormat;
60+
61+
/** Instantiates a new codec. */
62+
public BWCLucene87Codec() {
63+
super("BWCLucene87Codec");
64+
this.storedFieldsFormat = new Lucene87StoredFieldsFormat(Lucene87StoredFieldsFormat.Mode.BEST_COMPRESSION);
65+
this.defaultFormat = new Lucene84PostingsFormat();
66+
this.defaultDVFormat = new Lucene80DocValuesFormat(Lucene80DocValuesFormat.Mode.BEST_COMPRESSION);
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;
145+
146+
private final NormsFormat normsFormat = new Lucene80NormsFormat();
147+
148+
@Override
149+
public NormsFormat normsFormat() {
150+
return normsFormat;
151+
}
152+
153+
}

x-pack/plugin/old-lucene-versions/src/main/resources/META-INF/services/org.apache.lucene.codecs.Codec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# 2.0.
66
#
77

8+
org.elasticsearch.xpack.lucene.bwc.codecs.lucene87.BWCLucene87Codec
89
org.elasticsearch.xpack.lucene.bwc.codecs.lucene70.BWCLucene70Codec
910
org.elasticsearch.xpack.lucene.bwc.codecs.lucene70.Lucene70Codec
1011
org.elasticsearch.xpack.lucene.bwc.codecs.lucene62.Lucene62Codec

0 commit comments

Comments
 (0)