jaisonbi commented on a change in pull request #2213: URL: https://github.com/apache/lucene-solr/pull/2213#discussion_r564319900
########## File path: lucene/core/src/java/org/apache/lucene/codecs/lucene80/Lucene80DocValuesConsumer.java ########## @@ -791,6 +806,107 @@ private void addTermsDict(SortedSetDocValues values) throws IOException { writeTermsIndex(values); } + private void addCompressedTermsDict(SortedSetDocValues values) throws IOException { + final long size = values.getValueCount(); + meta.writeVLong(size); + meta.writeInt(Lucene80DocValuesFormat.TERMS_DICT_BLOCK_LZ4_CODE); + + ByteBuffersDataOutput addressBuffer = new ByteBuffersDataOutput(); + ByteBuffersIndexOutput addressOutput = + new ByteBuffersIndexOutput(addressBuffer, "temp", "temp"); + meta.writeInt(DIRECT_MONOTONIC_BLOCK_SHIFT); + long numBlocks = + (size + Lucene80DocValuesFormat.TERMS_DICT_BLOCK_LZ4_MASK) + >>> Lucene80DocValuesFormat.TERMS_DICT_BLOCK_LZ4_SHIFT; + DirectMonotonicWriter writer = + DirectMonotonicWriter.getInstance( + meta, addressOutput, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT); + + LZ4.FastCompressionHashTable ht = new LZ4.FastCompressionHashTable(); + ByteArrayDataOutput bufferedOutput = new ByteArrayDataOutput(termsDictBuffer); + long ord = 0; + long start = data.getFilePointer(); + int maxLength = 0; + TermsEnum iterator = values.termsEnum(); + int maxBlockLength = 0; + BytesRefBuilder previous = new BytesRefBuilder(); + for (BytesRef term = iterator.next(); term != null; term = iterator.next()) { + int termLength = term.length; + if ((ord & Lucene80DocValuesFormat.TERMS_DICT_BLOCK_LZ4_MASK) == 0) { + if (bufferedOutput.getPosition() > 0) { + int uncompressedLength = bufferedOutput.getPosition(); + data.writeVInt(uncompressedLength); + maxBlockLength = Math.max(maxBlockLength, uncompressedLength); + long before = data.getFilePointer(); + // Compress block + LZ4.compress(termsDictBuffer, 0, uncompressedLength, data, ht); + int compressedLength = (int) (data.getFilePointer() - before); + // Corner case: Compressed length might be bigger than un-compressed length. + maxBlockLength = Math.max(maxBlockLength, compressedLength); + bufferedOutput.reset(termsDictBuffer); + } + + writer.add(data.getFilePointer() - start); + data.writeVInt(termLength); + data.writeBytes(term.bytes, term.offset, termLength); + } else { + final int prefixLength = StringHelper.bytesDifference(previous.get(), term); + final int suffixLength = term.length - prefixLength; + assert suffixLength > 0; // terms are unique + int reservedSize = suffixLength + 11; // 1 byte + 2 vint. Review comment: makes sense, no need to introduce the new variable "reservedSize"... ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org