SOLR-792 -- write the value as an Object, not always a string

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1024323 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2010-10-19 17:03:42 +00:00
parent 933ebe5522
commit 054df4343c
2 changed files with 17 additions and 13 deletions

View File

@ -30,6 +30,10 @@ import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.FieldType; import org.apache.solr.schema.FieldType;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import java.io.IOException; import java.io.IOException;
@ -116,30 +120,30 @@ public class PivotFacetComponent extends SearchComponent
{ {
SolrIndexSearcher searcher = rb.req.getSearcher(); SolrIndexSearcher searcher = rb.req.getSearcher();
// TODO: optimize to avoid converting to an external string and then having to convert back to internal below // TODO: optimize to avoid converting to an external string and then having to convert back to internal below
FieldType ftype = null; FieldType ftype = searcher.getSchema().getField(field).getType();
// Required to translate back to an object
Field f = new Field( field, "X", Store.YES, Index.ANALYZED );
// SimpleFacets sf = getFacetImplementation(rb.req, docs, rb.req.getParams());
String nextField = fnames.poll(); String nextField = fnames.poll();
List<NamedList<Object>> values = new ArrayList<NamedList<Object>>( superFacets.size() ); List<NamedList<Object>> values = new ArrayList<NamedList<Object>>( superFacets.size() );
for (Map.Entry<String, Integer> kv : superFacets) { for (Map.Entry<String, Integer> kv : superFacets) {
// Only sub-facet if parent facet has positive count - still may not be any values for the sub-field though // Only sub-facet if parent facet has positive count - still may not be any values for the sub-field though
if (kv.getValue() > minMatch ) { if (kv.getValue() > minMatch ) {
String internal = ftype.toInternal( kv.getKey() );
f.setValue( internal );
SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>(); SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>();
pivot.add( "field", field ); pivot.add( "field", field );
pivot.add( "value", kv.getKey() ); pivot.add( "value", ftype.toObject( f ) );
pivot.add( "count", kv.getValue() ); pivot.add( "count", kv.getValue() );
if( subField == null ) { if( subField == null ) {
values.add( pivot ); values.add( pivot );
} }
else { else {
String s = kv.getKey(); Query query = new TermQuery(new Term(field, internal));
if( ftype == null ) {
ftype = searcher.getSchema().getField(field).getType();
}
Query query = new TermQuery(new Term(field, ftype.toInternal(s)));
DocSet subset = searcher.getDocSet(query, docs); DocSet subset = searcher.getDocSet(query, docs);
SimpleFacets sf = getFacetImplementation(rb.req, subset, rb.req.getParams()); SimpleFacets sf = getFacetImplementation(rb.req, subset, rb.req.getParams());

View File

@ -651,7 +651,7 @@ abstract public class SolrExampleTests extends SolrJettyTestBase
// p.write(System.out, 5 ); // p.write(System.out, 5 );
assertEquals( 1, counts.size() ); assertEquals( 1, counts.size() );
assertEquals( "inStock", counts.get(0).getField() ); assertEquals( "inStock", counts.get(0).getField() );
assertEquals( "true", counts.get(0).getValue() ); assertEquals( Boolean.TRUE, counts.get(0).getValue() );
assertEquals( 2, counts.get(0).getCount() ); assertEquals( 2, counts.get(0).getCount() );
} }