SOLR-6581: Additional test for Collapse and fixed problem with Expand float tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1651685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joel Bernstein 2015-01-14 14:35:03 +00:00
parent 7dff28a7bb
commit d095b85427
3 changed files with 79 additions and 3 deletions

View File

@ -1993,7 +1993,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
}
}
private class MergeBoost {
static class MergeBoost {
private int[] boostDocs;
private int index = 0;

View File

@ -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"};

View File

@ -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]");
}
}