gf2121 commented on code in PR #12587:
URL: https://github.com/apache/lucene/pull/12587#discussion_r1351349192


##########
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:
   Thanks for feedback!
   
   If using `MSBRadixSorter`, we need to override 
[`MSBRadixSorter#getFallbackSorter`](https://github.com/apache/lucene/blob/33a3af426003aea1dbcb60f2eeed35d47d65b9d7/lucene/core/src/java/org/apache/lucene/util/MSBRadixSorter.java#L69)
 to make the fallback sorter benefited from the vectorized equals, instead of 
the [default impl that comparing bytes one by 
one](https://github.com/apache/lucene/blob/33a3af426003aea1dbcb60f2eeed35d47d65b9d7/lucene/core/src/java/org/apache/lucene/util/MSBRadixSorter.java#L76C1-L88C8).
 
   
   We can avoid this with `StringSorter` as it is 
[implemented](https://github.com/apache/lucene/blob/33a3af426003aea1dbcb60f2eeed35d47d65b9d7/lucene/core/src/java/org/apache/lucene/util/StringSorter.java#L42)
 :)



-- 
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

Reply via email to