SOLR-1563: fix luke for binary fields

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@883178 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2009-11-22 22:57:08 +00:00
parent 4da546cc29
commit f23b570085
3 changed files with 68 additions and 9 deletions

View File

@ -61,6 +61,9 @@ Bug Fixes
* SOLR-1582: Fix BinaryField copy in DocumentBuilder (gsingers)
* SOLR-1563: Binary fields, including trie-based numeric fields, caused null
pointer exceptions in the luke request handler. (yonik)
Other Changes
----------------------

View File

@ -53,6 +53,7 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.Base64;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
@ -240,12 +241,20 @@ public class LukeRequestHandler extends RequestHandlerBase
f.add( "type", (ftype==null)?null:ftype.getTypeName() );
f.add( "schema", getFieldFlags( sfield ) );
f.add( "flags", getFieldFlags( fieldable ) );
Term t = new Term( fieldable.name(), fieldable.stringValue() );
Term t = new Term(fieldable.name(), ftype!=null ? ftype.storedToIndexed(fieldable) : fieldable.stringValue());
f.add( "value", (ftype==null)?null:ftype.toExternal( fieldable ) );
// TODO: this really should be "stored"
f.add( "internal", fieldable.stringValue() ); // may be a binary number
byte[] arr = fieldable.getBinaryValue();
if (arr != null) {
f.add( "binary", Base64.byteArrayToBase64(arr, 0, arr.length));
}
f.add( "boost", fieldable.getBoost() );
f.add( "docFreq", reader.docFreq( t ) ); // this can be 0 for non-indexed fields
f.add( "docFreq", t.text()==null ? 0 : reader.docFreq( t ) ); // this can be 0 for non-indexed fields
// If we have a term vector, return that
if( fieldable.isTermVectorStored() ) {

View File

@ -17,17 +17,25 @@
package org.apache.solr.handler.admin;
import junit.framework.TestCase;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.util.AbstractSolrTestCase;
/**
* :TODO: currently only tests some of the utilities in the LukeRequestHandler
*/
public class LukeRequestHandlerTest extends TestCase {
public class LukeRequestHandlerTest extends AbstractSolrTestCase {
@Override
public String getSchemaFile() {
return "schema12.xml";
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
}
/** tests some simple edge cases */
public void testHistogramPowerOfTwoBucket() {
public void doTestHistogramPowerOfTwoBucket() {
assertHistoBucket(1, 1);
assertHistoBucket(2, 2);
assertHistoBucket(4, 3);
@ -45,8 +53,47 @@ public class LukeRequestHandlerTest extends TestCase {
assertHistoBucket(MAX_VALID*2, MAX_VALID+1 );
}
private void assertHistoBucket(int expected, int in) {
assertEquals("histobucket: " + in, expected,
LukeRequestHandler.TermHistogram.getPowerOfTwoBucket( in ));
}
public void testLuke() {
doTestHistogramPowerOfTwoBucket();
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
assertQ(req("qt","/admin/luke", "id","SOLR1000"));
}
}