Apache Solr open-source search software
SOLR-6581: Additional test for Collapse and fixed problem with Expand float tests
Joel Bernsteind095b854273f
diff --git a/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.javaindex 834f5772515..0c54688428c 100644--- a/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java@@ -1993,7 +1993,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {}}- private class MergeBoost {+ static class MergeBoost {private int[] boostDocs;private int index = 0;diff --git a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.javaindex 19d9a649ac9..658fce2aa43 100644--- a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java+++ b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java@@ -71,6 +71,8 @@ public class TestExpandComponent extends SolrTestCaseJ4 {String floatAppend = "";if(groups.get(0).indexOf("f") > -1) {floatAppend = "."+random().nextInt(100); //Append the float+ floatAppend = Float.toString(Float.parseFloat(floatAppend)); //Create a proper float out of the string.+ floatAppend = floatAppend.substring(1); //Drop off the leading 0, leaving just the decimal}String hint = "";@@ -80,7 +82,13 @@ public class TestExpandComponent extends SolrTestCaseJ4 {private void _testExpand(String group, String floatAppend, String hint) throws Exception {- String[] doc = {"id","1", "term_s", "YYYY", group, "1"+floatAppend, "test_ti", "5", "test_tl", "10", "test_tf", "2000", "type_s", "parent"};+ String[] doc = {"id","1", "term_s", "YYYY", group, "1"+floatAppend, "test_ti", "5",++++++ "test_tl", "10", "test_tf", "2000", "type_s", "parent"};assertU(adoc(doc));assertU(commit());String[] doc1 = {"id","2", "term_s","YYYY", group, "1"+floatAppend, "test_ti", "50", "test_tl", "100", "test_tf", "200", "type_s", "child"};diff --git a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.javaindex 444ed299fbf..0f0b0a3b56a 100644--- a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java+++ b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java@@ -20,7 +20,10 @@ package org.apache.solr.search;import java.util.Collections;import java.util.List;import java.util.ArrayList;-import java.util.Random;+import java.util.Arrays;+import java.util.Set;+import java.util.HashSet;+import java.util.Iterator;import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;import org.apache.solr.SolrTestCaseJ4;@@ -74,6 +77,70 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 {testCollapseQueries(group, hint, true);}+ @Test++ public void testMergeBoost() throws Exception {++ Set<Integer> boosted = new HashSet();+ Set<Integer> results = new HashSet();++ for(int i=0; i<200; i++) {+ boosted.add(random().nextInt(1000));+ }++ for(int i=0; i<200; i++) {+ results.add(random().nextInt(1000));+ }++ int[] boostedArray = new int[boosted.size()];+ int[] resultsArray = new int[results.size()];++ Iterator<Integer> boostIt = boosted.iterator();+ int index = 0;+ while(boostIt.hasNext()) {+ boostedArray[index++] = boostIt.next();+ }++ Iterator<Integer> resultsIt = results.iterator();+ index = 0;+ while(resultsIt.hasNext()) {+ resultsArray[index++] = resultsIt.next();+ }++ Arrays.sort(boostedArray);+ Arrays.sort(resultsArray);++ CollapsingQParserPlugin.MergeBoost mergeBoost = new CollapsingQParserPlugin.MergeBoost(boostedArray);++ List<Integer> boostedResults = new ArrayList();++ for(int i=0; i<resultsArray.length; i++) {+ int result = resultsArray[i];+ if(mergeBoost.boost(result)) {+ boostedResults.add(result);+ }+ }++ List<Integer> controlResults = new ArrayList();++ for(int i=0; i<resultsArray.length; i++) {+ int result = resultsArray[i];+ if(Arrays.binarySearch(boostedArray, result) > -1) {+ controlResults.add(result);+ }+ }++ if(boostedResults.size() == controlResults.size()) {+ for(int i=0; i<boostedResults.size(); i++) {+ if(!boostedResults.get(i).equals(controlResults.get(i).intValue())) {+ throw new Exception("boosted results do not match control results, boostedResults size:"+boostedResults.toString()+", controlResults size:"+controlResults.toString());+ }+ }+ } else {+ throw new Exception("boosted results do not match control results, boostedResults size:"+boostedResults.toString()+", controlResults size:"+controlResults.toString());+ }+ }+private void testCollapseQueries(String group, String hint, boolean numeric) throws Exception {@@ -428,4 +495,5 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 {assertQ(req(params), "*[count(//doc)=0]");}+}