Skip to content

Commit

Permalink
port test from upstream PR; fix multivalued reuse bug (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
magibney authored and patsonluk committed Nov 24, 2023
1 parent c4b3214 commit 827cc02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,27 +63,14 @@ protected void after() {
}
};

private static String fieldConfig(String fieldName, boolean multivalued) {
return "<field name=\""
+ fieldName
+ "\" type=\"string\" indexed=\"false\" stored=\"false\" docValues=\"true\" useDocValuesAsStored=\"true\" multiValued=\""
+ multivalued
+ "\"/>\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(
"</schema>", fieldConfig(SINGLE, false) + fieldConfig(MULTI, true) + "</schema>"));
Files.copy(
TEST_PATH().resolve("collection1/conf/schema-docValuesMulti.xml"),
configSet.resolve("conf/schema.xml"),
StandardCopyOption.REPLACE_EXISTING);

solrClientTestRule.newCollection().withConfigSet(configSet.toString()).create();

Expand All @@ -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<String> getFields = Set.of(SINGLE, MULTI);
Map<String, SolrDocumentFetcher.DVIterEntry> dvIterCache = new HashMap<>();
final Set<String> getFields = Set.of("stringdv");
final SolrDocument doc = new SolrDocument();
for (int i = DOC_COUNT * 10; i >= 0; i--) {
int checkId = r.nextInt(DOC_COUNT);
Expand All @@ -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<Object> 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<Object> actualVals = doc.getFieldValues("stringdv");
assertEquals(expected.length, actualVals.size());
int j = 0;
for (Object o : actualVals) {
assertEquals(expected[j++], o);
}
Expand All @@ -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) {
Expand Down

0 comments on commit 827cc02

Please sign in to comment.