diff --git a/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java index 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.java index 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.java index 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 boosted = new HashSet(); + Set 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 boostIt = boosted.iterator(); + int index = 0; + while(boostIt.hasNext()) { + boostedArray[index++] = boostIt.next(); + } + + Iterator 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 boostedResults = new ArrayList(); + + for(int i=0; i controlResults = new ArrayList(); + + for(int i=0; i -1) { + controlResults.add(result); + } + } + + if(boostedResults.size() == controlResults.size()) { + for(int i=0; i