Apache Solr open-source search software
SOLR-17631: Fixing field cache ords counting, fixes TestFieldCache and TestFieldCacheVsDocValues
Ishan Chattopadhyayad3d7d05122fc
diff --git a/solr/core/src/java/org/apache/solr/uninverting/DocTermOrds.java b/solr/core/src/java/org/apache/solr/uninverting/DocTermOrds.javaindex 74d886c0235..55071e4d856 100644--- a/solr/core/src/java/org/apache/solr/uninverting/DocTermOrds.java+++ b/solr/core/src/java/org/apache/solr/uninverting/DocTermOrds.java@@ -816,9 +816,10 @@ public class DocTermOrds implements Accountable {// This value was inlined, and then read into a single bufferreturn bufferLength;} else {- // scan logic taken from read()+ // scan logic taken from read() - count the number of term ordinalsint start = index[doc] & 0x7fffffff;int cursor = start;+ int count = 0;for (; ; ) {int delta = 0;for (; ; ) {@@ -827,9 +828,10 @@ public class DocTermOrds implements Accountable {if ((b & 0x80) == 0) break;}if (delta == 0) break;+ count++;}- return cursor - start - 1;+ return count;}}diff --git a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCache.java b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCache.javaindex c0d7985955f..9c6bb0a9969 100644--- a/solr/core/src/test/org/apache/solr/uninverting/TestFieldCache.java+++ b/solr/core/src/test/org/apache/solr/uninverting/TestFieldCache.java@@ -269,22 +269,22 @@ public class TestFieldCache extends SolrTestCase {termOrds = cache.getDocTermOrds(reader, "theRandomUnicodeMultiValuedField", null);assertEquals(numEntries, cache.getCacheEntries().length);- for (int i = 0; i < NUM_DOCS; i++) {+ int doc;+ while ((doc = termOrds.nextDoc()) != NO_MORE_DOCS) {// This will remove identical terms. A DocTermOrds doesn't return duplicate ords for a docId- List<BytesRef> values = new ArrayList<>(new LinkedHashSet<>(Arrays.asList(multiValued[i])));+ List<BytesRef> values = new ArrayList<>(new LinkedHashSet<>(Arrays.asList(multiValued[doc])));+ int processedValues = 0;for (BytesRef v : values) {if (v == null) {// why does this test use null values... instead of an empty list: confusingbreak;}- if (i > termOrds.docID()) {- assertEquals(i, termOrds.nextDoc());- }long ord = termOrds.nextOrd();BytesRef scratch = termOrds.lookupOrd(ord);assertEquals(v, scratch);+ processedValues++;}- assertEquals(i, termOrds.docValueCount());+ assertEquals(processedValues, termOrds.docValueCount());}// test bad field