@@ -185,33 +185,38 @@ public BinaryDocValues getBinary(FieldInfo field) throws IOException {
185185
186186 final RandomAccessInput bytesSlice = data .randomAccessSlice (entry .dataOffset , entry .dataLength );
187187
188+ final int maxCompressedLength = entry .maxCompressedLength ;
189+ final int lengthToAllocate = entry .maxLength + 7 ; // uncompressed
188190 if (entry .docsWithFieldOffset == -1 ) {
191+
189192 // dense
190- if (entry .minLength == entry .maxLength ) {
193+ if (entry .minCompressedLength == entry .maxCompressedLength ) {
191194 // fixed length
192- final int length = entry .maxLength ;
193195 return new DenseBinaryDocValues (maxDoc ) {
194- final BytesRef bytes = new BytesRef (new byte [length ], 0 , length );
195-
196+ final BytesRef inBuf = new BytesRef (new byte [maxCompressedLength ], 0 , maxCompressedLength );
197+ final BytesRef outBuf = new BytesRef ( new byte [ lengthToAllocate ], 0 , lengthToAllocate );
196198 @ Override
197199 public BytesRef binaryValue () throws IOException {
198- bytesSlice .readBytes ((long ) doc * length , bytes .bytes , 0 , length );
199- return bytes ;
200+ bytesSlice .readBytes ((long ) doc * maxCompressedLength , inBuf .bytes , 0 , maxCompressedLength );
201+ outBuf .length = FSST .decompress (inBuf .bytes , 0 , inBuf .length , entry .decoder , outBuf .bytes );
202+ return outBuf ;
200203 }
201204 };
202205 } else {
203206 // variable length
204207 final RandomAccessInput addressesData = this .data .randomAccessSlice (entry .addressesOffset , entry .addressesLength );
205- final LongValues addresses = DirectMonotonicReader .getInstance (entry .addressesMeta , addressesData , merging );
208+ final LongValues addresses = DirectMonotonicReader .getInstance (entry .addressesMeta , addressesData );
206209 return new DenseBinaryDocValues (maxDoc ) {
207- final BytesRef bytes = new BytesRef (new byte [entry .maxLength ], 0 , entry .maxLength );
210+ final BytesRef inBuf = new BytesRef (new byte [maxCompressedLength ], 0 , 0 );
211+ final BytesRef outBuf = new BytesRef (new byte [lengthToAllocate ], 0 , lengthToAllocate );
208212
209213 @ Override
210214 public BytesRef binaryValue () throws IOException {
211215 long startOffset = addresses .get (doc );
212- bytes .length = (int ) (addresses .get (doc + 1L ) - startOffset );
213- bytesSlice .readBytes (startOffset , bytes .bytes , 0 , bytes .length );
214- return bytes ;
216+ inBuf .length = (int ) (addresses .get (doc + 1L ) - startOffset );
217+ bytesSlice .readBytes (startOffset , inBuf .bytes , 0 , inBuf .length );
218+ outBuf .length = FSST .decompress (inBuf .bytes , 0 , inBuf .length , entry .decoder , outBuf .bytes );
219+ return outBuf ;
215220 }
216221 };
217222 }
@@ -225,32 +230,34 @@ public BytesRef binaryValue() throws IOException {
225230 entry .denseRankPower ,
226231 entry .numDocsWithField
227232 );
228- if (entry .minLength == entry .maxLength ) {
233+ if (entry .minCompressedLength == entry .maxCompressedLength ) {
229234 // fixed length
230- final int length = entry .maxLength ;
231235 return new SparseBinaryDocValues (disi ) {
232- final BytesRef bytes = new BytesRef (new byte [length ], 0 , length );
236+ final BytesRef inBuf = new BytesRef (new byte [maxCompressedLength ], 0 , entry .maxCompressedLength );
237+ final BytesRef outBuf = new BytesRef (new byte [lengthToAllocate ], 0 , lengthToAllocate );
233238
234239 @ Override
235240 public BytesRef binaryValue () throws IOException {
236- bytesSlice .readBytes ((long ) disi .index () * length , bytes .bytes , 0 , length );
237- return bytes ;
241+ bytesSlice .readBytes ((long ) disi .index () * maxCompressedLength , inBuf .bytes , 0 , maxCompressedLength );
242+ outBuf .length = FSST .decompress (inBuf .bytes , 0 , inBuf .length , entry .decoder , outBuf .bytes );
243+ return outBuf ;
238244 }
239245 };
240246 } else {
241247 // variable length
242248 final RandomAccessInput addressesData = this .data .randomAccessSlice (entry .addressesOffset , entry .addressesLength );
243- final LongValues addresses = DirectMonotonicReader .getInstance (entry .addressesMeta , addressesData , merging );
249+ final LongValues addresses = DirectMonotonicReader .getInstance (entry .addressesMeta , addressesData );
244250 return new SparseBinaryDocValues (disi ) {
245- final BytesRef bytes = new BytesRef (new byte [entry . maxLength ], 0 , entry . maxLength );
246-
251+ final BytesRef inBuf = new BytesRef (new byte [maxCompressedLength ], 0 , 0 );
252+ final BytesRef outBuf = new BytesRef ( new byte [ lengthToAllocate ], 0 , lengthToAllocate );
247253 @ Override
248254 public BytesRef binaryValue () throws IOException {
249255 final int index = disi .index ();
250256 long startOffset = addresses .get (index );
251- bytes .length = (int ) (addresses .get (index + 1L ) - startOffset );
252- bytesSlice .readBytes (startOffset , bytes .bytes , 0 , bytes .length );
253- return bytes ;
257+ inBuf .length = (int ) (addresses .get (index + 1L ) - startOffset );
258+ bytesSlice .readBytes (startOffset , inBuf .bytes , 0 , inBuf .length );
259+ outBuf .length = FSST .decompress (inBuf .bytes , 0 , inBuf .length , entry .decoder , outBuf .bytes );
260+ return outBuf ;
254261 }
255262 };
256263 }
@@ -954,7 +961,12 @@ private BinaryEntry readBinary(IndexInput meta) throws IOException {
954961 entry .numDocsWithField = meta .readInt ();
955962 entry .minLength = meta .readInt ();
956963 entry .maxLength = meta .readInt ();
957- if (entry .minLength < entry .maxLength ) {
964+
965+ entry .minCompressedLength = meta .readInt ();
966+ entry .maxCompressedLength = meta .readInt ();
967+ entry .decoder = FSST .Decoder .readFrom (meta ::readByte );
968+
969+ if (entry .minCompressedLength < entry .maxCompressedLength ) {
958970 entry .addressesOffset = meta .readLong ();
959971
960972 // Old count of uncompressed addresses
0 commit comments