|
7 | 7 |
|
8 | 8 | import com.google.common.collect.ImmutableMap;
|
9 | 9 | import com.google.common.collect.Maps;
|
| 10 | +import lombok.Builder; |
10 | 11 | import org.apache.lucene.codecs.Codec;
|
11 | 12 | import org.apache.lucene.codecs.CodecUtil;
|
12 | 13 | import org.apache.lucene.codecs.DocValuesProducer;
|
|
52 | 53 |
|
53 | 54 | public class KNNCodecTestUtil {
|
54 | 55 |
|
55 |
| - // Utility class to help build SegmentInfo with reasonable defaults |
56 |
| - public static class SegmentInfoBuilder { |
57 |
| - |
58 |
| - private final Directory directory; |
59 |
| - private final String segmentName; |
60 |
| - private final int docsInSegment; |
61 |
| - private final Codec codec; |
62 |
| - |
63 |
| - private Version version; |
64 |
| - private Version minVersion; |
65 |
| - private boolean isCompoundFile; |
66 |
| - private byte[] segmentId; |
67 |
| - private final Map<String, String> attributes; |
68 |
| - private Sort indexSort; |
69 |
| - |
70 |
| - public static SegmentInfoBuilder builder(Directory directory, String segmentName, int docsInSegment, Codec codec) { |
71 |
| - return new SegmentInfoBuilder(directory, segmentName, docsInSegment, codec); |
72 |
| - } |
73 |
| - |
74 |
| - private SegmentInfoBuilder(Directory directory, String segmentName, int docsInSegment, Codec codec) { |
75 |
| - this.directory = directory; |
76 |
| - this.segmentName = segmentName; |
77 |
| - this.docsInSegment = docsInSegment; |
78 |
| - this.codec = codec; |
79 |
| - |
80 |
| - this.version = Version.LATEST; |
81 |
| - this.minVersion = Version.LATEST; |
82 |
| - this.isCompoundFile = false; |
83 |
| - this.segmentId = randomByteArrayOfLength(StringHelper.ID_LENGTH); |
84 |
| - this.attributes = new HashMap<>(); |
85 |
| - this.indexSort = Sort.INDEXORDER; |
86 |
| - } |
87 |
| - |
88 |
| - public SegmentInfoBuilder version(Version version) { |
89 |
| - this.version = version; |
90 |
| - return this; |
91 |
| - } |
92 |
| - |
93 |
| - public SegmentInfoBuilder minVersion(Version minVersion) { |
94 |
| - this.minVersion = minVersion; |
95 |
| - return this; |
96 |
| - } |
97 |
| - |
98 |
| - public SegmentInfoBuilder isCompoundFile(boolean isCompoundFile) { |
99 |
| - this.isCompoundFile = isCompoundFile; |
100 |
| - return this; |
101 |
| - } |
102 |
| - |
103 |
| - public SegmentInfoBuilder segmentId(byte[] segmentId) { |
104 |
| - this.segmentId = segmentId; |
105 |
| - return this; |
106 |
| - } |
107 |
| - |
108 |
| - public SegmentInfoBuilder addAttribute(String key, String value) { |
109 |
| - this.attributes.put(key, value); |
110 |
| - return this; |
111 |
| - } |
112 |
| - |
113 |
| - public SegmentInfoBuilder indexSort(Sort indexSort) { |
114 |
| - this.indexSort = indexSort; |
115 |
| - return this; |
116 |
| - } |
117 |
| - |
118 |
| - public SegmentInfo build() { |
119 |
| - return new SegmentInfo( |
120 |
| - directory, |
121 |
| - version, |
122 |
| - minVersion, |
123 |
| - segmentName, |
124 |
| - docsInSegment, |
125 |
| - isCompoundFile, |
126 |
| - codec, |
127 |
| - Collections.emptyMap(), |
128 |
| - segmentId, |
129 |
| - attributes, |
130 |
| - indexSort |
131 |
| - ); |
132 |
| - } |
133 |
| - } |
134 |
| - |
135 | 56 | // Utility class to help build FieldInfo
|
136 | 57 | public static class FieldInfoBuilder {
|
137 | 58 | private final String fieldName;
|
@@ -430,4 +351,21 @@ public static float[] getRandomVector(int dimension) {
|
430 | 351 | }
|
431 | 352 | return data;
|
432 | 353 | }
|
| 354 | + |
| 355 | + @Builder(builderMethodName = "segmentInfoBuilder") |
| 356 | + public static SegmentInfo newSegmentInfo(final Directory directory, final String segmentName, int docsInSegment, final Codec codec) { |
| 357 | + return new SegmentInfo( |
| 358 | + directory, |
| 359 | + Version.LATEST, |
| 360 | + Version.LATEST, |
| 361 | + segmentName, |
| 362 | + docsInSegment, |
| 363 | + false, |
| 364 | + codec, |
| 365 | + Collections.emptyMap(), |
| 366 | + randomByteArrayOfLength(StringHelper.ID_LENGTH), |
| 367 | + ImmutableMap.of(), |
| 368 | + Sort.INDEXORDER |
| 369 | + ); |
| 370 | + } |
433 | 371 | }
|
0 commit comments