nick-boss-tech commented on code in PR #5339:
URL: https://github.com/apache/solr/pull/5339#discussion_r4581696955


##########
solr/core/src/java/org/apache/solr/update/processor/TextProfileSignature.java:
##########
@@ -151,7 +151,11 @@ public String toString() {
   private static class TokenComparator implements Comparator<Token> {
     @Override
     public int compare(Token t1, Token t2) {
-      return t2.cnt - t1.cnt;
+      int c = Integer.compare(t2.cnt, t1.cnt);
+      if (c != 0) {
+        return c;
+      }
+      return t1.val.compareTo(t2.val);

Review Comment:
   🤖 *AI text below* 🤖 *(reviewed by Nick Shanin)*
   
   This can change the signature for profiles whose tied tokens previously had 
a different order. Existing documents keep their old signatures, so 
`overwriteDupes` may no longer match them. If the signature is the unique key, 
a later add can also get a different ID.
   
   Could the upgrade notes explain this effect for users of 
`TextProfileSignature` and when they may need to rebuild their index?



##########
solr/core/src/test/org/apache/solr/update/processor/TextProfileSignatureTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.update.processor;
+
+import java.util.HexFormat;
+import java.util.Locale;
+import java.util.Map;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.params.MapSolrParams;
+import org.junit.Test;
+
+public class TextProfileSignatureTest extends SolrTestCase {
+
+  private static TextProfileSignature newSignature() {
+    TextProfileSignature sig = new TextProfileSignature();
+    sig.init(new MapSolrParams(Map.of()));
+    return sig;
+  }
+
+  private static byte[] signatureOf(String content) {
+    TextProfileSignature sig = newSignature();
+    sig.add(content);
+    return sig.getSignature();
+  }
+
+  private static String hex(byte[] bytes) {
+    return HexFormat.of().formatHex(bytes);
+  }
+
+  @Test
+  public void testIdenticalContentSameSignature() {
+    String content = "the quick brown fox jumps over the lazy dog";
+    assertArrayEquals(signatureOf(content), signatureOf(content));
+  }
+
+  @Test
+  public void testSignatureStableAcrossHashMapResize() {
+    String[] head = {"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"};
+    StringBuilder base = new StringBuilder();
+    for (String token : head) {
+      for (int i = 0; i < 200; i++) {
+        if (!base.isEmpty()) {
+          base.append(' ');
+        }
+        base.append(token);
+      }
+    }
+
+    byte[] expected = signatureOf(base.toString());
+    for (int n = 0; n < 80; n++) {
+      StringBuilder text = new StringBuilder(base);
+      for (int i = 0; i <= n; i++) {
+        text.append(' ').append("xpad").append(String.format(Locale.ROOT, 
"%04d", i));
+      }
+      byte[] actual = signatureOf(text.toString());
+      assertArrayEquals(

Review Comment:
   🤖 *AI text below* 🤖 *(reviewed by Nick Shanin)*
   
   The resize test covers the reported failure. Could the tests also assert a 
known signature for a profile with different frequencies and a tie after 
quantization? That would check the intended frequency order and tie-break as 
well as stability.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to