gsmiller commented on code in PR #12587: URL: https://github.com/apache/lucene/pull/12587#discussion_r1350774457
########## lucene/core/src/java/org/apache/lucene/search/TermInSetQuery.java: ########## @@ -112,7 +113,23 @@ private static PrefixCodedTerms packTerms(String field, Collection<BytesRef> ter boolean sorted = terms instanceof SortedSet && ((SortedSet<BytesRef>) terms).comparator() == null; if (sorted == false) { - ArrayUtil.timSort(sortedTerms); + new StringSorter(BytesRefComparator.NATURAL) { + + @Override + protected void get(BytesRefBuilder builder, BytesRef result, int i) { + BytesRef term = sortedTerms[i]; + result.length = term.length; + result.offset = term.offset; + result.bytes = term.bytes; + } + + @Override + protected void swap(int i, int j) { + BytesRef b = sortedTerms[i]; + sortedTerms[i] = sortedTerms[j]; + sortedTerms[j] = b; + } + }.sort(0, sortedTerms.length); Review Comment: I wonder if we could (should?) use radix sort directly instead of going through `StringSorter`? We don't need the fallback sort logic that StringSorter provides right? Then we could avoid the API visibility change. Maybe there's a good reason though to go through StringSorter I'm missing? I _think_ this would do the trick though right? ``` new MSBRadixSorter(Integer.MAX_VALUE) { @Override protected int byteAt(int i, int k) { BytesRef b = sortedTerms[i]; if (b.length <= k) { return -1; } return b.bytes[b.offset + k] & 0xFF; } @Override protected void swap(int i, int j) { BytesRef b = sortedTerms[i]; sortedTerms[i] = sortedTerms[j]; sortedTerms[j] = b; } }.sort(0, sortedTerms.length); ``` -- 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