mirror of https://github.com/apache/lucene.git
SOLR-3150: NPE when facetting using facet.prefix on an empty field
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1292007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bde0264a26
commit
f50e4dbf51
|
@ -227,7 +227,7 @@ public class UnInvertedField extends DocTermOrds {
|
||||||
int endTerm = numTermsInField; // one past the end
|
int endTerm = numTermsInField; // one past the end
|
||||||
|
|
||||||
TermsEnum te = getOrdTermsEnum(searcher.getAtomicReader());
|
TermsEnum te = getOrdTermsEnum(searcher.getAtomicReader());
|
||||||
if (prefix != null && prefix.length() > 0) {
|
if (te != null && prefix != null && prefix.length() > 0) {
|
||||||
final BytesRef prefixBr = new BytesRef(prefix);
|
final BytesRef prefixBr = new BytesRef(prefix);
|
||||||
if (te.seekCeil(prefixBr, true) == TermsEnum.SeekStatus.END) {
|
if (te.seekCeil(prefixBr, true) == TermsEnum.SeekStatus.END) {
|
||||||
startTerm = numTermsInField;
|
startTerm = numTermsInField;
|
||||||
|
|
|
@ -17,12 +17,17 @@
|
||||||
|
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.request;
|
||||||
|
|
||||||
|
import org.apache.noggit.ObjectBuilder;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class SimpleFacetsTest extends SolrTestCaseJ4 {
|
public class SimpleFacetsTest extends SolrTestCaseJ4 {
|
||||||
|
@ -53,7 +58,9 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void createIndex() {
|
static void createIndex() throws Exception {
|
||||||
|
doEmptyFacetCounts(); // try on empty index
|
||||||
|
|
||||||
indexSimpleFacetCounts();
|
indexSimpleFacetCounts();
|
||||||
indexDateFacets();
|
indexDateFacets();
|
||||||
indexFacetSingleValued();
|
indexFacetSingleValued();
|
||||||
|
@ -95,6 +102,67 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
|
||||||
"zerolen_s","");
|
"zerolen_s","");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyFacetCounts() throws Exception {
|
||||||
|
doEmptyFacetCounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
// static so we can try both with and without an empty index
|
||||||
|
static void doEmptyFacetCounts() throws Exception {
|
||||||
|
doEmptyFacetCounts("empty_t", new String[]{null, "myprefix",""});
|
||||||
|
doEmptyFacetCounts("empty_i", new String[]{null});
|
||||||
|
doEmptyFacetCounts("empty_f", new String[]{null});
|
||||||
|
doEmptyFacetCounts("empty_s", new String[]{null, "myprefix",""});
|
||||||
|
doEmptyFacetCounts("empty_d", new String[]{null});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void doEmptyFacetCounts(String field, String[] prefixes) throws Exception {
|
||||||
|
SchemaField sf = h.getCore().getSchema().getField(field);
|
||||||
|
|
||||||
|
String response = JQ(req("q", "*:*"));
|
||||||
|
Map rsp = (Map) ObjectBuilder.fromJSON(response);
|
||||||
|
Long numFound = (Long)(((Map)rsp.get("response")).get("numFound"));
|
||||||
|
|
||||||
|
ModifiableSolrParams params = params("q","*:*", "rows","0", "facet","true", "facet.field","{!key=myalias}"+field);
|
||||||
|
|
||||||
|
String[] methods = {null, "fc","enum","fcs"};
|
||||||
|
if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
|
||||||
|
methods = new String[]{null, "fc","enum"};
|
||||||
|
}
|
||||||
|
|
||||||
|
prefixes = prefixes==null ? new String[]{null} : prefixes;
|
||||||
|
|
||||||
|
|
||||||
|
for (String method : methods) {
|
||||||
|
if (method == null) {
|
||||||
|
params.remove("facet.method");
|
||||||
|
} else {
|
||||||
|
params.set("facet.method", method);
|
||||||
|
}
|
||||||
|
for (String prefix : prefixes) {
|
||||||
|
if (prefix == null) {
|
||||||
|
params.remove("facet.prefix");
|
||||||
|
} else {
|
||||||
|
params.set("facet.prefix", prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String missing : new String[] {null, "true"}) {
|
||||||
|
if (missing == null) {
|
||||||
|
params.remove("facet.missing");
|
||||||
|
} else {
|
||||||
|
params.set("facet.missing", missing);
|
||||||
|
}
|
||||||
|
|
||||||
|
String expected = missing==null ? "[]" : "[null," + numFound + "]";
|
||||||
|
|
||||||
|
assertJQ(req(params),
|
||||||
|
"/facet_counts/facet_fields/myalias==" + expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleFacetCounts() {
|
public void testSimpleFacetCounts() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue