From 827cc0282a81bead117f8cc3219aebe57260d0fb Mon Sep 17 00:00:00 2001 From: Michael Gibney Date: Wed, 20 Sep 2023 10:23:47 -0700 Subject: [PATCH] port test from upstream PR; fix multivalued reuse bug (#146) --- .../solr/search/SolrDocumentFetcher.java | 4 ++ .../search/TestDocValuesIteratorCache.java | 47 +++++++------------ 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java index a04a0d0d59b..7693ee4ac75 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java @@ -899,6 +899,8 @@ public SortedNumericDocValues getSortedNumericDocValues( dv = sndvs[leafOrd]; int currentDoc = dv.docID(); if (localId == currentDoc && !consumed[leafOrd]) { + consumed[leafOrd] = true; + noMatchSince[leafOrd] = DocIdSetIterator.NO_MORE_DOCS; return dv; } else if (localId <= currentDoc) { if (localId >= noMatchSince[leafOrd]) { @@ -949,6 +951,8 @@ public SortedSetDocValues getSortedSetDocValues(int localId, LeafReader leafRead dv = ssdvs[leafOrd]; int currentDoc = dv.docID(); if (localId == currentDoc && !consumed[leafOrd]) { + consumed[leafOrd] = true; + noMatchSince[leafOrd] = DocIdSetIterator.NO_MORE_DOCS; return dv; } else if (localId <= currentDoc) { if (localId >= noMatchSince[leafOrd]) { diff --git a/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java b/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java index 338be897c70..38f163833a5 100644 --- a/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java +++ b/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java @@ -20,7 +20,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.Random; import java.util.Set; import org.apache.lucene.tests.util.LuceneTestCase; @@ -60,27 +63,14 @@ protected void after() { } }; - private static String fieldConfig(String fieldName, boolean multivalued) { - return "\n"; - } - - private static final String SINGLE = "single"; - private static final String MULTI = "multi"; - @SuppressWarnings("try") public void test() throws Exception { Path configSet = LuceneTestCase.createTempDir(); SolrTestCaseJ4.copyMinConf(configSet.toFile()); - Path schemaXml = configSet.resolve("conf/schema.xml"); - Files.writeString( - schemaXml, - Files.readString(schemaXml) - .replace( - "", fieldConfig(SINGLE, false) + fieldConfig(MULTI, true) + "")); + Files.copy( + TEST_PATH().resolve("collection1/conf/schema-docValuesMulti.xml"), + configSet.resolve("conf/schema.xml"), + StandardCopyOption.REPLACE_EXISTING); solrClientTestRule.newCollection().withConfigSet(configSet.toString()).create(); @@ -96,8 +86,8 @@ public void test() throws Exception { SolrIndexSearcher s = sref.get(); assertEquals(DOC_COUNT, s.maxDoc()); SolrDocumentFetcher docFetcher = s.getDocFetcher(); - DocValuesIteratorCache dvIterCache = new DocValuesIteratorCache(s); - final Set getFields = Set.of(SINGLE, MULTI); + Map dvIterCache = new HashMap<>(); + final Set getFields = Set.of("stringdv"); final SolrDocument doc = new SolrDocument(); for (int i = DOC_COUNT * 10; i >= 0; i--) { int checkId = r.nextInt(DOC_COUNT); @@ -107,12 +97,10 @@ public void test() throws Exception { if (expected == null) { assertTrue(doc.isEmpty()); } else { - assertEquals(2, doc.size()); - Object singleValue = doc.getFieldValue(SINGLE); - Collection actualVals = doc.getFieldValues(MULTI); - assertEquals(expected.length, actualVals.size() + 1); // +1 for single-valued field - assertEquals(expected[0], singleValue); - int j = 1; + assertEquals(1, doc.size()); + Collection actualVals = doc.getFieldValues("stringdv"); + assertEquals(expected.length, actualVals.size()); + int j = 0; for (Object o : actualVals) { assertEquals(expected[j++], o); } @@ -130,17 +118,16 @@ private String[][] indexDocs(SolrClient client, Random r) if (r.nextInt(100) > pct) { client.add(sdoc("id", Integer.toString(i))); } else { - String str = TestUtil.randomSimpleString(r); String str1 = TestUtil.randomSimpleString(r); String str2 = TestUtil.randomSimpleString(r); - client.add(sdoc("id", Integer.toString(i), SINGLE, str, MULTI, str1, MULTI, str2)); + client.add(sdoc("id", Integer.toString(i), "stringdv", str1, "stringdv", str2)); int cmp = str1.compareTo(str2); if (cmp == 0) { - ret[i] = new String[] {str, str1}; + ret[i] = new String[] {str1}; } else if (cmp < 0) { - ret[i] = new String[] {str, str1, str2}; + ret[i] = new String[] {str1, str2}; } else { - ret[i] = new String[] {str, str2, str1}; + ret[i] = new String[] {str2, str1}; } } if (r.nextInt(DOC_COUNT / 5) == 0) {