Fix for SOLR-3111 - fl param not working when more than one field was specified. Also honors * for "all fields"

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1242150 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erick Erickson 2012-02-08 22:30:50 +00:00
parent 534ecb309b
commit 3f9389b3ea
2 changed files with 75 additions and 33 deletions

View File

@ -99,9 +99,11 @@ public class LukeRequestHandler extends RequestHandlerBase
// If no doc is given, show all fields and top terms // If no doc is given, show all fields and top terms
Set<String> fields = null; Set<String> fields = null;
if( params.get( CommonParams.FL ) != null ) { String fl = params.get(CommonParams.FL);
fields = new TreeSet<String>(Arrays.asList(params.getParams( CommonParams.FL ))); if (fl != null) {
fields = new TreeSet<String>(Arrays.asList(fl.split( "[,\\s]+" )));
} }
if ( "schema".equals( params.get( "show" ))) { if ( "schema".equals( params.get( "show" ))) {
numTerms = 0; // Abort any statistics gathering. numTerms = 0; // Abort any statistics gathering.
} }
@ -300,7 +302,7 @@ public class LukeRequestHandler extends RequestHandlerBase
Fields theFields = reader.fields(); Fields theFields = reader.fields();
for (String fieldName : fieldNames) { for (String fieldName : fieldNames) {
if (fields != null && ! fields.contains(fieldName)) { if (fields != null && ! fields.contains(fieldName) && ! fields.contains("*")) {
continue; // we're not interested in this term continue; // we're not interested in this term
} }
@ -522,7 +524,7 @@ public class LukeRequestHandler extends RequestHandlerBase
} }
totalTerms += terms.getUniqueTermCount(); totalTerms += terms.getUniqueTermCount();
if (fieldList != null && !fieldList.contains(field)) { if (fieldList != null && ! fieldList.contains(field) && ! fieldList.contains("*")) {
continue; continue;
} }

View File

@ -18,7 +18,9 @@
package org.apache.solr.handler.admin; package org.apache.solr.handler.admin;
import org.apache.solr.common.luke.FieldFlag; import org.apache.solr.common.luke.FieldFlag;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.EnumSet; import java.util.EnumSet;
@ -39,6 +41,40 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
return "solrconfig.xml"; return "solrconfig.xml";
} }
@Before
public void before() {
assertU(adoc("id","SOLR1000", "name","Apache Solr",
"solr_si", "10",
"solr_sl", "10",
"solr_sf", "10",
"solr_sd", "10",
"solr_s", "10",
"solr_sI", "10",
"solr_sS", "10",
"solr_t", "10",
"solr_tt", "10",
"solr_b", "true",
"solr_i", "10",
"solr_l", "10",
"solr_f", "10",
"solr_d", "10",
"solr_ti", "10",
"solr_tl", "10",
"solr_tf", "10",
"solr_td", "10",
"solr_pi", "10",
"solr_pl", "10",
"solr_pf", "10",
"solr_pd", "10",
"solr_dt", "2000-01-01T01:01:01Z",
"solr_tdt", "2000-01-01T01:01:01Z",
"solr_pdt", "2000-01-01T01:01:01Z"
));
assertU(commit());
}
@Test
public void testHistogramBucket() { public void testHistogramBucket() {
assertHistoBucket(0, 1); assertHistoBucket(0, 1);
assertHistoBucket(1, 2); assertHistoBucket(1, 2);
@ -65,34 +101,6 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
@Test @Test
public void testLuke() { public void testLuke() {
assertU(adoc("id","SOLR1000", "name","Apache Solr",
"solr_si", "10",
"solr_sl", "10",
"solr_sf", "10",
"solr_sd", "10",
"solr_s", "10",
"solr_sI", "10",
"solr_sS", "10",
"solr_t", "10",
"solr_tt", "10",
"solr_b", "true",
"solr_i", "10",
"solr_l", "10",
"solr_f", "10",
"solr_d", "10",
"solr_ti", "10",
"solr_tl", "10",
"solr_tf", "10",
"solr_td", "10",
"solr_pi", "10",
"solr_pl", "10",
"solr_pf", "10",
"solr_pd", "10",
"solr_dt", "2000-01-01T01:01:01Z",
"solr_tdt", "2000-01-01T01:01:01Z",
"solr_pdt", "2000-01-01T01:01:01Z"
));
assertU(commit());
// test that Luke can handle all of the field types // test that Luke can handle all of the field types
assertQ(req("qt","/admin/luke", "id","SOLR1000")); assertQ(req("qt","/admin/luke", "id","SOLR1000"));
@ -138,5 +146,37 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
private static String getFieldXPathPrefix(String field) { private static String getFieldXPathPrefix(String field) {
return "//lst[@name='fields']/lst[@name='"+field+"']/str"; return "//lst[@name='fields']/lst[@name='"+field+"']/str";
} }
@Test
public void testFlParam() {
SolrQueryRequest req = req("qt", "/admin/luke", "fl", "solr_t solr_s");
try {
// First, determine that the two fields ARE there
String response = h.query(req);
assertNull(h.validateXPath(response,
getFieldXPathPrefix("solr_t") + "[@name='index']",
getFieldXPathPrefix("solr_s") + "[@name='index']"
));
// Now test that the other fields are NOT there
for (String f : Arrays.asList("solr_ti",
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
assertNotNull(h.validateXPath(response,
getFieldXPathPrefix(f) + "[@name='index']"));
}
// Insure * works
req = req("qt", "/admin/luke", "fl", "*");
response = h.query(req);
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti",
"solr_td", "solr_pl", "solr_dt", "solr_b")) {
assertNull(h.validateXPath(response,
getFieldXPathPrefix(f) + "[@name='index']"));
}
} catch (Exception e) {
fail("Caught unexpected exception " + e.getMessage());
}
}
} }