mirror of https://github.com/apache/lucene.git
SOLR-5488: Changing Facets testing to use DOM rather than string operations
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b821c13488
commit
38643894d1
|
@ -17,8 +17,10 @@
|
|||
|
||||
package org.apache.solr.analytics.facet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -35,6 +37,18 @@ import org.apache.solr.request.SolrQueryRequest;
|
|||
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import org.apache.solr.util.ExternalPaths;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
@SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Appending","Asserting"})
|
||||
public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
|
||||
|
@ -42,24 +56,84 @@ public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
|
|||
|
||||
protected String latestType = "";
|
||||
|
||||
public String getFacetXML(String response, String requestName, String facetType, String facet) {
|
||||
String cat = "\n <lst name=\""+requestName+"\">";
|
||||
String begin = " <lst name=\""+facetType+"\">\n";
|
||||
String end = "\n </lst>";
|
||||
int beginInt = response.indexOf(begin, response.indexOf(cat))+begin.length();
|
||||
int endInt = response.indexOf(end, beginInt);
|
||||
String fieldStr = response.substring(beginInt, endInt);
|
||||
begin = " <lst name=\""+facet+"\">";
|
||||
end = "\n </lst>";
|
||||
beginInt = fieldStr.indexOf(begin);
|
||||
endInt = fieldStr.indexOf(end, beginInt);
|
||||
String facetStr = "";
|
||||
if (beginInt>=0) {
|
||||
facetStr = fieldStr.substring(beginInt+begin.length(),endInt);
|
||||
}
|
||||
return facetStr+" ";
|
||||
private static Document doc;
|
||||
private static XPathFactory xPathFact = XPathFactory.newInstance();
|
||||
private static String rawResponse;
|
||||
|
||||
protected static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true); // never forget this!
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8"))));
|
||||
xPathFact = XPathFactory.newInstance();
|
||||
rawResponse = response;
|
||||
}
|
||||
|
||||
protected String getRawResponse() {
|
||||
return rawResponse;
|
||||
}
|
||||
|
||||
protected Node getNode(String xPath) throws XPathExpressionException {
|
||||
return (Node)xPathFact.newXPath().compile(xPath).evaluate(doc, XPathConstants.NODE);
|
||||
}
|
||||
private NodeList getNodes(String n1, String n2, String n3, String element, String n4) throws XPathExpressionException {
|
||||
// Construct the XPath expression. The form better not change or all these will fail.
|
||||
StringBuilder sb = new StringBuilder("/response/lst[@name='stats']/lst[@name='").append(n1).append("']");
|
||||
sb.append("/lst[@name='").append(n2).append("']");
|
||||
sb.append("/lst[@name='").append(n3).append("']");
|
||||
sb.append("//").append(element).append("[@name='").append(n4).append("']");
|
||||
return (NodeList)xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
|
||||
|
||||
}
|
||||
protected ArrayList<String> getStringList(String n1, String n2, String n3, String element, String n4)
|
||||
throws XPathExpressionException {
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
NodeList nodes = getNodes(n1, n2, n3, element, n4);
|
||||
for (int idx = 0; idx < nodes.getLength(); ++idx) {
|
||||
ret.add(nodes.item(idx).getTextContent());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected ArrayList<Integer> getIntegerList(String n1, String n2, String n3, String element, String n4)
|
||||
throws XPathExpressionException {
|
||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
||||
NodeList nodes = getNodes(n1, n2, n3, element, n4);
|
||||
for (int idx = 0; idx < nodes.getLength(); ++idx) {
|
||||
ret.add(Integer.parseInt(nodes.item(idx).getTextContent()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
protected ArrayList<Long> getLongList(String n1, String n2, String n3, String element, String n4)
|
||||
throws XPathExpressionException {
|
||||
ArrayList<Long> ret = new ArrayList<Long>();
|
||||
NodeList nodes = getNodes(n1, n2, n3, element, n4);
|
||||
for (int idx = 0; idx < nodes.getLength(); ++idx) {
|
||||
ret.add(Long.parseLong(nodes.item(idx).getTextContent()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
protected ArrayList<Float> getFloatList(String n1, String n2, String n3, String element, String n4)
|
||||
throws XPathExpressionException {
|
||||
ArrayList<Float> ret = new ArrayList<Float>();
|
||||
NodeList nodes = getNodes(n1, n2, n3, element, n4);
|
||||
for (int idx = 0; idx < nodes.getLength(); ++idx) {
|
||||
ret.add(Float.parseFloat(nodes.item(idx).getTextContent()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected ArrayList<Double> getDoubleList(String n1, String n2, String n3, String element, String n4)
|
||||
throws XPathExpressionException {
|
||||
ArrayList<Double> ret = new ArrayList<Double>();
|
||||
NodeList nodes = getNodes(n1, n2, n3, element, n4);
|
||||
for (int idx = 0; idx < nodes.getLength(); ++idx) {
|
||||
ret.add(Double.parseDouble(nodes.item(idx).getTextContent()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static void increment(List<Long> list, int idx){
|
||||
Long i = list.remove(idx);
|
||||
list.add(idx, i+1);
|
||||
|
@ -84,41 +158,6 @@ public class AbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
|
|||
this.latestType = latestType;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public ArrayList xmlToList(String facit, String type, String name) {
|
||||
ArrayList list;
|
||||
if (type.equals("double")) {
|
||||
list = new ArrayList<Double>();
|
||||
} else if (type.equals("int")) {
|
||||
list = new ArrayList<Integer>();
|
||||
} else if (type.equals("long")) {
|
||||
list = new ArrayList<Long>();
|
||||
} else if (type.equals("float")) {
|
||||
list = new ArrayList<Float>();
|
||||
} else {
|
||||
list = new ArrayList<String>();
|
||||
}
|
||||
String find = "<"+type+" name=\""+name+"\">";
|
||||
String endS = "</"+type+">";
|
||||
int findAt = facit.indexOf(find)+find.length();
|
||||
while (findAt>find.length()) {
|
||||
int end = facit.indexOf(endS, findAt);
|
||||
if (type.equals("double")) {
|
||||
list.add(Double.parseDouble(facit.substring(findAt, end)));
|
||||
} else if (type.equals("int")) {
|
||||
list.add(Integer.parseInt(facit.substring(findAt, end)));
|
||||
} else if (type.equals("long")) {
|
||||
list.add(Long.parseLong(facit.substring(findAt, end)));
|
||||
} else if (type.equals("float")) {
|
||||
list.add(Float.parseFloat(facit.substring(findAt, end)));
|
||||
} else {
|
||||
list.add(facit.substring(findAt, end));
|
||||
}
|
||||
findAt = facit.indexOf(find, end)+find.length();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T extends Number & Comparable<T>> ArrayList calculateNumberStat(ArrayList<ArrayList<T>> lists, String stat) {
|
||||
ArrayList result;
|
||||
|
|
|
@ -45,8 +45,6 @@ public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {
|
|||
static ArrayList<ArrayList<Integer>> intDoubleTestStart;
|
||||
static ArrayList<ArrayList<Integer>> intStringTestStart;
|
||||
|
||||
static String response;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig-basic.xml","schema-analytics.xml");
|
||||
|
@ -106,85 +104,72 @@ public class FieldFacetExtrasTest extends AbstractAnalyticsFacetTest {
|
|||
}
|
||||
|
||||
assertU(commit());
|
||||
response = h.query(request(fileToStringArr(fileName)));
|
||||
setResponse(h.query(request(fileToStringArr(fileName))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void limitTest() throws Exception {
|
||||
|
||||
String longLimit = getFacetXML(response, "lr", "fieldFacets", "long_ld");
|
||||
Collection<Double> lon = (ArrayList<Double>)xmlToList(longLimit, "double", "mean");
|
||||
assertEquals(lon.size(),5);
|
||||
String floatLimit = getFacetXML(response, "lr", "fieldFacets", "float_fd");
|
||||
Collection<Double> flo = (ArrayList<Double>)xmlToList(floatLimit, "double", "median");
|
||||
assertEquals(flo.size(),3);
|
||||
String doubleLimit = getFacetXML(response, "lr", "fieldFacets", "double_dd");
|
||||
Collection<Long> doub = (ArrayList<Long>)xmlToList(doubleLimit, "long", "count");
|
||||
assertEquals(doub.size(),7);
|
||||
String stringLimit = getFacetXML(response, "lr", "fieldFacets", "string_sd");
|
||||
Collection<Integer> string = (ArrayList<Integer>)xmlToList(stringLimit, "int", "percentile_20");
|
||||
assertEquals(string.size(),1);
|
||||
Collection<Double> lon = getDoubleList("lr", "fieldFacets", "long_ld", "double", "mean");
|
||||
assertEquals(getRawResponse(), lon.size(),5);
|
||||
Collection<Double> flo = getDoubleList("lr", "fieldFacets", "float_fd", "double", "median");
|
||||
assertEquals(getRawResponse(), flo.size(),3);
|
||||
Collection<Long> doub = getLongList("lr", "fieldFacets", "double_dd", "long", "count");
|
||||
assertEquals(getRawResponse(), doub.size(),7);
|
||||
Collection<Integer> string = getIntegerList("lr", "fieldFacets", "string_sd", "int", "percentile_20");
|
||||
assertEquals(getRawResponse(), string.size(),1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void offsetTest() throws Exception {
|
||||
|
||||
String xml;
|
||||
Collection<Double> lon;
|
||||
|
||||
List<Double> all = new ArrayList<Double>();
|
||||
xml = getFacetXML(response, "off0", "fieldFacets", "long_ld");
|
||||
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean");
|
||||
assertEquals(lon.size(),2);
|
||||
lon = getDoubleList("off0", "fieldFacets", "long_ld", "double", "mean");
|
||||
assertEquals(getRawResponse(), lon.size(),2);
|
||||
assertArrayEquals(new Double[]{ 1.5, 2.0 }, lon.toArray(new Double[0]));
|
||||
all.addAll(lon);
|
||||
|
||||
xml = getFacetXML(response, "off1", "fieldFacets", "long_ld");
|
||||
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean");
|
||||
assertEquals(lon.size(),2);
|
||||
lon = getDoubleList("off1", "fieldFacets", "long_ld", "double", "mean");
|
||||
assertEquals(getRawResponse(), lon.size(),2);
|
||||
assertArrayEquals(new Double[]{ 3.0, 4.0 }, lon.toArray(new Double[0]));
|
||||
all.addAll(lon);
|
||||
|
||||
xml = getFacetXML(response, "off2", "fieldFacets", "long_ld");
|
||||
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean");
|
||||
assertEquals(lon.size(),3);
|
||||
lon = getDoubleList("off2", "fieldFacets", "long_ld", "double", "mean");
|
||||
assertEquals(getRawResponse(), lon.size(),3);
|
||||
assertArrayEquals(new Double[]{ 5.0, 5.75, 6.0 }, lon.toArray(new Double[0]));
|
||||
all.addAll(lon);
|
||||
|
||||
xml = getFacetXML(response, "offAll", "fieldFacets", "long_ld");
|
||||
lon = (ArrayList<Double>)xmlToList(xml, "double", "mean");
|
||||
assertEquals(lon.size(),7);
|
||||
lon = getDoubleList("offAll", "fieldFacets", "long_ld", "double", "mean");
|
||||
assertEquals(getRawResponse(), lon.size(),7);
|
||||
assertArrayEquals(all.toArray(new Double[0]), lon.toArray(new Double[0]));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void sortTest() throws Exception {
|
||||
String longSort = getFacetXML(response, "sr", "fieldFacets", "long_ld");
|
||||
Collection<Double> lon = (ArrayList<Double>)xmlToList(longSort, "double", "mean");
|
||||
Collection<Double> lon = getDoubleList("sr", "fieldFacets", "long_ld", "double", "mean");
|
||||
ArrayList<Double> longTest = calculateNumberStat(intLongTestStart, "mean");
|
||||
Collections.sort(longTest);
|
||||
assertEquals(longTest,lon);
|
||||
assertEquals(getRawResponse(), longTest,lon);
|
||||
|
||||
String floatSort = getFacetXML(response, "sr", "fieldFacets", "float_fd");
|
||||
Collection<Double> flo = (ArrayList<Double>)xmlToList(floatSort, "double", "median");
|
||||
Collection<Double> flo = getDoubleList("sr", "fieldFacets", "float_fd", "double", "median");
|
||||
ArrayList<Double> floatTest = calculateNumberStat(intFloatTestStart, "median");
|
||||
Collections.sort(floatTest,Collections.reverseOrder());
|
||||
assertEquals(floatTest,flo);
|
||||
assertEquals(getRawResponse(), floatTest,flo);
|
||||
|
||||
String doubleSort = getFacetXML(response, "sr", "fieldFacets", "double_dd");
|
||||
Collection<Long> doub = (ArrayList<Long>)xmlToList(doubleSort, "long", "count");
|
||||
Collection<Long> doub = getLongList("sr", "fieldFacets", "double_dd", "long", "count");
|
||||
ArrayList<Long> doubleTest = (ArrayList<Long>)calculateStat(intDoubleTestStart, "count");
|
||||
Collections.sort(doubleTest);
|
||||
assertEquals(doubleTest,doub);
|
||||
assertEquals(getRawResponse(), doubleTest,doub);
|
||||
|
||||
String stringSort = getFacetXML(response, "sr", "fieldFacets", "string_sd");
|
||||
Collection<Integer> string = (ArrayList<Integer>)xmlToList(stringSort, "int", "percentile_20");
|
||||
Collection<Integer> string = getIntegerList("sr", "fieldFacets", "string_sd", "int", "percentile_20");
|
||||
ArrayList<Integer> stringTest = (ArrayList<Integer>)calculateStat(intStringTestStart, "perc_20");
|
||||
Collections.sort(stringTest,Collections.reverseOrder());
|
||||
assertEquals(stringTest,string);
|
||||
assertEquals(getRawResponse(), stringTest,string);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -102,30 +102,26 @@ public class QueryFacetTest extends AbstractAnalyticsFacetTest {
|
|||
assertU(commit());
|
||||
|
||||
//Query ascending tests
|
||||
String response = h.query(request(fileToStringArr(fileName)));
|
||||
setResponse(h.query(request(fileToStringArr(fileName))));
|
||||
|
||||
//Int One
|
||||
String int1Query = getFacetXML(response, "ir", "queryFacets", "float1");
|
||||
ArrayList<Double> int1 = (ArrayList<Double>)xmlToList(int1Query, "double", "sum");
|
||||
ArrayList<Double> int1 = getDoubleList("ir", "queryFacets", "float1", "double", "sum");
|
||||
ArrayList<Double> int1Test = calculateNumberStat(int1TestStart, "sum");
|
||||
assertEquals(int1,int1Test);
|
||||
assertEquals(getRawResponse(), int1, int1Test);
|
||||
//Int Two
|
||||
String int2Query = getFacetXML(response, "ir", "queryFacets", "float2");
|
||||
ArrayList<Integer> int2 = (ArrayList<Integer>)xmlToList(int2Query, "int", "percentile_8");
|
||||
ArrayList<Integer> int2 = getIntegerList("ir", "queryFacets", "float2", "int", "percentile_8");
|
||||
ArrayList<Integer> int2Test = (ArrayList<Integer>)calculateStat(int2TestStart, "perc_8");
|
||||
assertEquals(int2,int2Test);
|
||||
assertEquals(getRawResponse(), int2, int2Test);
|
||||
|
||||
//Long
|
||||
String long1Query = getFacetXML(response, "lr", "queryFacets", "string");
|
||||
ArrayList<Double> long1 = (ArrayList<Double>)xmlToList(long1Query, "double", "median");
|
||||
ArrayList<Double> long1 = getDoubleList("lr", "queryFacets", "string", "double", "median");
|
||||
ArrayList<Double> long1Test = calculateNumberStat(longTestStart, "median");
|
||||
assertEquals(long1,long1Test);
|
||||
assertEquals(getRawResponse(),long1,long1Test);
|
||||
|
||||
//Float
|
||||
String float1Query = getFacetXML(response, "fr", "queryFacets", "lad");
|
||||
ArrayList<Double> float1 = (ArrayList<Double>)xmlToList(float1Query, "double", "mean");
|
||||
ArrayList<Double> float1 = getDoubleList("fr", "queryFacets", "lad", "double", "mean");
|
||||
ArrayList<Double> float1Test = calculateNumberStat(floatTestStart, "mean");
|
||||
assertEquals(float1,float1Test);
|
||||
assertEquals(getRawResponse(), float1, float1Test);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
|
|||
static ArrayList<ArrayList<Float>> floatDoubleTestStart;
|
||||
static ArrayList<ArrayList<Float>> floatDateTestStart;
|
||||
|
||||
static String response;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig-basic.xml","schema-analytics.xml");
|
||||
|
@ -117,7 +115,7 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
|
|||
|
||||
assertU(commit());
|
||||
|
||||
response = h.query(request(fileToStringArr(fileName)));
|
||||
setResponse(h.query(request(fileToStringArr(fileName))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -125,42 +123,36 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
|
|||
public void rangeTest() throws Exception {
|
||||
|
||||
//Int Long
|
||||
String intLongRange = getFacetXML(response, "ri", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "long", "count");
|
||||
ArrayList<Long> intLong = getLongList("ri", "rangeFacets", "long_ld", "long", "count");
|
||||
ArrayList<Long> intLongTest = calculateStat(transformLists(intLongTestStart, 5, 30, 5
|
||||
, false, true, false, false, false), "count");
|
||||
assertEquals(intLong,intLongTest);
|
||||
assertEquals(getRawResponse(), intLong,intLongTest);
|
||||
//Int Double
|
||||
String intDoubleRange = getFacetXML(response, "ri", "rangeFacets", "double_dd");
|
||||
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
|
||||
ArrayList<Double> intDouble = getDoubleList("ri", "rangeFacets", "double_dd", "double", "mean");
|
||||
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
|
||||
, false, false, true, false, true), "mean");
|
||||
assertEquals(intDouble,intDoubleTest);
|
||||
assertEquals(getRawResponse(), intDouble,intDoubleTest);
|
||||
//Int Date
|
||||
String intDateRange = getFacetXML(response, "ri", "rangeFacets", "date_dtd");
|
||||
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
|
||||
ArrayList<Long> intDate = getLongList("ri", "rangeFacets", "date_dtd", "long", "count");
|
||||
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
|
||||
, false, true, false, true, true), "count");
|
||||
assertEquals(intDate,intDateTest);
|
||||
assertEquals(getRawResponse(), intDate,intDateTest);
|
||||
|
||||
//Float Long
|
||||
String floatLongRange = getFacetXML(response, "rf", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
|
||||
ArrayList<Double> floatLong = getDoubleList("rf", "rangeFacets", "long_ld", "double", "median");
|
||||
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
|
||||
, false, true, true, true, true), "median");
|
||||
assertEquals(floatLong,floatLongTest);
|
||||
assertEquals(getRawResponse(), floatLong,floatLongTest);
|
||||
//Float Double
|
||||
String floatDoubleRange = getFacetXML(response, "rf", "rangeFacets", "double_dd");
|
||||
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
|
||||
ArrayList<Long> floatDouble = getLongList("rf", "rangeFacets", "double_dd", "long", "count");
|
||||
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
|
||||
, false, false, false, true, false), "count");
|
||||
assertEquals(floatDouble,floatDoubleTest);
|
||||
assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
|
||||
//Float Date
|
||||
String floatDateRange = getFacetXML(response, "rf", "rangeFacets", "date_dtd");
|
||||
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDate = getDoubleList("rf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5
|
||||
, false, false, true, true, false), "sumOfSquares");
|
||||
assertEquals(floatDate,floatDateTest);
|
||||
assertEquals(getRawResponse(), floatDate,floatDateTest);
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,84 +160,72 @@ public class RangeFacetTest extends AbstractAnalyticsFacetTest {
|
|||
@Test
|
||||
public void hardendRangeTest() throws Exception {
|
||||
//Int Long
|
||||
String intLongRange = getFacetXML(response, "hi", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "double", "sum");
|
||||
ArrayList<Double> intLong = getDoubleList("hi", "rangeFacets", "long_ld", "double", "sum");
|
||||
ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, 5
|
||||
, true, true, false, false, false), "sum");
|
||||
assertEquals(intLong,intLongTest);
|
||||
assertEquals(getRawResponse(), intLong,intLongTest);
|
||||
//Int Double
|
||||
String intDoubleRange = getFacetXML(response, "hi", "rangeFacets", "double_dd");
|
||||
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
|
||||
ArrayList<Double> intDouble = getDoubleList("hi", "rangeFacets", "double_dd", "double", "mean");
|
||||
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, 7
|
||||
, true, false, true, false, true), "mean");
|
||||
assertEquals(intDouble,intDoubleTest);
|
||||
assertEquals(getRawResponse(), intDouble,intDoubleTest);
|
||||
//Int Date
|
||||
String intDateRange = getFacetXML(response, "hi", "rangeFacets", "date_dtd");
|
||||
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
|
||||
ArrayList<Long> intDate = getLongList("hi", "rangeFacets", "date_dtd", "long", "count");
|
||||
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, 7
|
||||
, true, true, false, true, true), "count");
|
||||
assertEquals(intDate,intDateTest);
|
||||
assertEquals(getRawResponse(), intDate,intDateTest);
|
||||
|
||||
//Float Long
|
||||
String floatLongRange = getFacetXML(response, "hf", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
|
||||
ArrayList<Double> floatLong = getDoubleList("hf", "rangeFacets", "long_ld", "double", "median");
|
||||
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, 4
|
||||
, true, true, true, true, true), "median");
|
||||
assertEquals(floatLong,floatLongTest);
|
||||
assertEquals(getRawResponse(), floatLong,floatLongTest);
|
||||
//Float Double
|
||||
String floatDoubleRange = getFacetXML(response, "hf", "rangeFacets", "double_dd");
|
||||
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
|
||||
ArrayList<Long> floatDouble = getLongList("hf", "rangeFacets", "double_dd", "long", "count");
|
||||
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, 11
|
||||
, true, false, false, true, false), "count");
|
||||
assertEquals(floatDouble,floatDoubleTest);
|
||||
assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
|
||||
//Float Date
|
||||
String floatDateRange = getFacetXML(response, "hf", "rangeFacets", "date_dtd");
|
||||
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDate = getDoubleList("hf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, 5
|
||||
, true, false, true, true, false), "sumOfSquares");
|
||||
assertEquals(floatDate,floatDateTest);
|
||||
assertEquals(getRawResponse(), floatDate,floatDateTest);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void multiGapTest() throws Exception {
|
||||
//Int Long
|
||||
String intLongRange = getFacetXML(response, "mi", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> intLong = (ArrayList<Double>)xmlToList(intLongRange, "double", "sum");
|
||||
ArrayList<Double> intLong = getDoubleList("mi", "rangeFacets", "long_ld", "double", "sum");
|
||||
ArrayList<Double> intLongTest = calculateNumberStat(transformLists(intLongTestStart, 5, 30, "4,2,6,3"
|
||||
, false, true, false, false, false), "sum");
|
||||
assertEquals(intLong,intLongTest);
|
||||
assertEquals(getRawResponse(), intLong,intLongTest);
|
||||
//Int Double
|
||||
String intDoubleRange = getFacetXML(response, "mi", "rangeFacets", "double_dd");
|
||||
ArrayList<Double> intDouble = (ArrayList<Double>)xmlToList(intDoubleRange, "double", "mean");
|
||||
ArrayList<Double> intDouble = getDoubleList("mi", "rangeFacets", "double_dd", "double", "mean");
|
||||
ArrayList<Double> intDoubleTest = calculateNumberStat(transformLists(intDoubleTestStart, 3, 39, "3,1,7"
|
||||
, false, false, true, false, true), "mean");
|
||||
assertEquals(intDouble,intDoubleTest);
|
||||
assertEquals(getRawResponse(), intDouble,intDoubleTest);
|
||||
//Int Date
|
||||
String intDateRange = getFacetXML(response, "mi", "rangeFacets", "date_dtd");
|
||||
ArrayList<Long> intDate = (ArrayList<Long>)xmlToList(intDateRange, "long", "count");
|
||||
ArrayList<Long> intDate = getLongList("mi", "rangeFacets", "date_dtd", "long", "count");
|
||||
ArrayList<Long> intDateTest = (ArrayList<Long>)calculateStat(transformLists(intDateTestStart, 7, 44, "2,7"
|
||||
, false, true, false, true, true), "count");
|
||||
assertEquals(intDate,intDateTest);
|
||||
assertEquals(getRawResponse(), intDate,intDateTest);
|
||||
|
||||
//Float Long
|
||||
String floatLongRange = getFacetXML(response, "mf", "rangeFacets", "long_ld");
|
||||
ArrayList<Double> floatLong = (ArrayList<Double>)xmlToList(floatLongRange, "double", "median");
|
||||
ArrayList<Double> floatLong = getDoubleList("mf", "rangeFacets", "long_ld", "double", "median");
|
||||
ArrayList<Double> floatLongTest = calculateNumberStat(transformLists(floatLongTestStart, 0, 29, "1,4"
|
||||
, false, true, true, true, true), "median");;
|
||||
assertEquals(floatLong,floatLongTest);
|
||||
assertEquals(getRawResponse(), floatLong,floatLongTest);
|
||||
//Float Double
|
||||
String floatDoubleRange = getFacetXML(response, "mf", "rangeFacets", "double_dd");
|
||||
ArrayList<Long> floatDouble = (ArrayList<Long>)xmlToList(floatDoubleRange, "long", "count");
|
||||
ArrayList<Long> floatDouble = getLongList("mf", "rangeFacets", "double_dd", "long", "count");
|
||||
ArrayList<Long> floatDoubleTest = (ArrayList<Long>)calculateStat(transformLists(floatDoubleTestStart, 4, 47, "2,3,11"
|
||||
, false, false, false, true, false), "count");
|
||||
assertEquals(floatDouble,floatDoubleTest);
|
||||
assertEquals(getRawResponse(), floatDouble,floatDoubleTest);
|
||||
//Float Date
|
||||
String floatDateRange = getFacetXML(response, "mf", "rangeFacets", "date_dtd");
|
||||
ArrayList<Double> floatDate = (ArrayList<Double>)xmlToList(floatDateRange, "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDate = getDoubleList("mf", "rangeFacets", "date_dtd", "double", "sumOfSquares");
|
||||
ArrayList<Double> floatDateTest = calculateNumberStat(transformLists(floatDateTestStart, 4, 46, "4,5"
|
||||
, false, false, true, true, false), "sumOfSquares");
|
||||
assertEquals(floatDate,floatDateTest);
|
||||
assertEquals(getRawResponse(), floatDate,floatDateTest);
|
||||
}
|
||||
|
||||
private <T> ArrayList<ArrayList<T>> transformLists(ArrayList<ArrayList<T>> listsStart, int start, int end, int gap
|
||||
|
|
Loading…
Reference in New Issue