SOLR-5107: Fixed NPE when using numTerms=0 in LukeRequestHandler

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1511064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-08-06 18:26:27 +00:00
parent 8256f80523
commit eb104d2190
3 changed files with 28 additions and 2 deletions

View File

@ -100,6 +100,9 @@ Bug Fixes
when generating collations involving multiple word-break corrections.
(James Dyer)
* SOLR-5107: Fixed NPE when using numTerms=0 in LukeRequestHandler
(Ahmet Arslan, hossman)
Optimizations
----------------------

View File

@ -576,7 +576,7 @@ public class LukeRequestHandler extends RequestHandlerBase
throws IOException {
SolrParams params = req.getParams();
int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT );
final int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT );
TopTermQueue tiq = new TopTermQueue(numTerms + 1); // Something to collect the top N terms in.
@ -600,7 +600,7 @@ public class LukeRequestHandler extends RequestHandlerBase
int freq = termsEnum.docFreq(); // This calculation seems odd, but it gives the same results as it used to.
int slot = 32 - Integer.numberOfLeadingZeros(Math.max(0, freq - 1));
buckets[slot] = buckets[slot] + 1;
if (freq > tiq.minFreq) {
if (numTerms > 0 && freq > tiq.minFreq) {
UnicodeUtil.UTF8toUTF16(text, spare);
String t = spare.toString();

View File

@ -184,6 +184,29 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
}
}
public void testNumTerms() throws Exception {
final String f = "name";
for (String n : new String[] {"2", "3", "100", "99999"}) {
assertQ(req("qt", "/admin/luke", "fl", f, "numTerms", n),
field(f) + "lst[@name='topTerms']/int[@name='Apache']",
field(f) + "lst[@name='topTerms']/int[@name='Solr']",
"count("+field(f)+"lst[@name='topTerms']/int)=2");
}
assertQ(req("qt", "/admin/luke", "fl", f, "numTerms", "1"),
// no garuntee which one we find
"count("+field(f)+"lst[@name='topTerms']/int)=1");
assertQ(req("qt", "/admin/luke", "fl", f, "numTerms", "0"),
"count("+field(f)+"lst[@name='topTerms']/int)=0");
// field with no terms shouldn't error
for (String n : new String[] {"0", "1", "2", "100", "99999"}) {
assertQ(req("qt", "/admin/luke", "fl", "bogus_s", "numTerms", n),
"count("+field(f)+"lst[@name='topTerms']/int)=0");
}
}
public void testCopyFieldLists() throws Exception {
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema");