Skip to content

Apache Lucene open-source search software

SOLR-2089: fixed tests + exception when facet.offset is beyond queue size

Yonik Seeley44468e02bf3c
diff --git a/solr/src/java/org/apache/solr/request/UnInvertedField.java b/solr/src/java/org/apache/solr/request/UnInvertedField.java
index 708b55be393..0c470bc4947 100755
--- a/solr/src/java/org/apache/solr/request/UnInvertedField.java
+++ b/solr/src/java/org/apache/solr/request/UnInvertedField.java
@@ -600,8 +600,10 @@ public class UnInvertedField {
// now select the right page from the results
- final int[] tnums = new int[Math.min(queue.size()-off, lim)];
+ final int[] tnums = new int[Math.min(Math.max(0, queue.size()-off), lim)];
final int[] indirect = counts; // reuse the counts array for the index into the tnums array
+ assert indirect.length >= tnums.length;
+
int tnumCount = 0;
for (Long p : queue) {
diff --git a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
index 615685ab33a..3fdd75c0581 100755
--- a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
@@ -315,12 +315,24 @@ public class SolrTestCaseJ4 extends LuceneTestCaseJ4 {
try {
String m = (null == message) ? "" : message + " ";
String response = h.query(req);
+
+ if (req.getParams().getBool("facet", false)) {
+ // add a test to ensure that faceting did not throw an exception
+ // internally, where it would be added to facet_counts/exception
+ String[] allTests = new String[tests.length+1];
+ System.arraycopy(tests,0,allTests,1,tests.length);
+ allTests[0] = "*[count(//lst[@name='facet_counts']/*[@name='exception'])=0]";
+ tests = allTests;
+ }
+
String results = h.validateXPath(response, tests);
+
if (null != results) {
fail(m + "query failed XPath: " + results +
"\n xml response was: " + response +
"\n request was: " + req.getParamString());
}
+
} catch (XPathExpressionException e1) {
throw new RuntimeException("XPath is invalid", e1);
} catch (Exception e2) {