jpountz commented on code in PR #12829: URL: https://github.com/apache/lucene/pull/12829#discussion_r1419268112
########## lucene/core/src/java/org/apache/lucene/index/IndexingChain.java: ########## @@ -219,15 +222,33 @@ private Sorter.DocMap maybeSortSegment(SegmentWriteState state) throws IOExcepti } LeafReader docValuesReader = getDocValuesLeafReader(); - + Function<IndexSorter.DocComparator, IndexSorter.DocComparator> comparatorWrapper = in -> in; + + if (state.segmentInfo.getHasBlocks() && indexSort.getParentField() != null) { + final DocIdSetIterator readerValues = + docValuesReader.getNumericDocValues(indexSort.getParentField()); + BitSet parents = BitSet.of(readerValues, state.segmentInfo.maxDoc()); + comparatorWrapper = + in -> + (docID1, docID2) -> + in.compare(parents.nextSetBit(docID1), parents.nextSetBit(docID2)); + } + assert state.segmentInfo.getHasBlocks() == false + || indexSort.getParentField() != null + || indexCreatedVersionMajor < Version.LUCENE_10_0_0.major + : "parent field is not set but the index has blocks. indexCreatedVersionMajor: " + + indexCreatedVersionMajor; List<IndexSorter.DocComparator> comparators = new ArrayList<>(); for (int i = 0; i < indexSort.getSort().length; i++) { SortField sortField = indexSort.getSort()[i]; IndexSorter sorter = sortField.getIndexSorter(); if (sorter == null) { throw new UnsupportedOperationException("Cannot sort index using sort field " + sortField); } - comparators.add(sorter.getDocComparator(docValuesReader, state.segmentInfo.maxDoc())); + + IndexSorter.DocComparator docComparator = Review Comment: It's been a long time so I don't know if/where this is tested, I just know that we need stability for other reasons, e.g. to preserve some merging optimizations by having runs of doc IDs that come from the same segment that are as long as possible. -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org 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