From 054df4343c79936e9965937a70baa5b9f2390f59 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 19 Oct 2010 17:03:42 +0000 Subject: [PATCH] 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 --- .../component/PivotFacetComponent.java | 24 +++++++++++-------- .../solr/client/solrj/SolrExampleTests.java | 6 ++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/solr/src/java/org/apache/solr/handler/component/PivotFacetComponent.java b/solr/src/java/org/apache/solr/handler/component/PivotFacetComponent.java index d271265c2e1..d8790284f77 100644 --- a/solr/src/java/org/apache/solr/handler/component/PivotFacetComponent.java +++ b/solr/src/java/org/apache/solr/handler/component/PivotFacetComponent.java @@ -30,6 +30,10 @@ import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.schema.FieldType; import org.apache.lucene.search.Query; 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 java.io.IOException; @@ -116,30 +120,30 @@ public class PivotFacetComponent extends SearchComponent { SolrIndexSearcher searcher = rb.req.getSearcher(); // 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(); List> values = new ArrayList>( superFacets.size() ); for (Map.Entry kv : superFacets) { // 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 pivot = new SimpleOrderedMap(); pivot.add( "field", field ); - pivot.add( "value", kv.getKey() ); + pivot.add( "value", ftype.toObject( f ) ); pivot.add( "count", kv.getValue() ); if( subField == null ) { values.add( pivot ); } else { - String s = kv.getKey(); - if( ftype == null ) { - ftype = searcher.getSchema().getField(field).getType(); - } - - Query query = new TermQuery(new Term(field, ftype.toInternal(s))); + Query query = new TermQuery(new Term(field, internal)); DocSet subset = searcher.getDocSet(query, docs); SimpleFacets sf = getFacetImplementation(rb.req, subset, rb.req.getParams()); diff --git a/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java index 0d23f8bf474..3975e9d0ce5 100644 --- a/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java +++ b/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java @@ -650,9 +650,9 @@ abstract public class SolrExampleTests extends SolrJettyTestBase counts = p.getPivot(); // p.write(System.out, 5 ); assertEquals( 1, counts.size() ); - assertEquals( "inStock", counts.get(0).getField() ); - assertEquals( "true", counts.get(0).getValue() ); - assertEquals( 2, counts.get(0).getCount() ); + assertEquals( "inStock", counts.get(0).getField() ); + assertEquals( Boolean.TRUE, counts.get(0).getValue() ); + assertEquals( 2, counts.get(0).getCount() ); } public static SolrInputDocument makeTestDoc( Object ... kvp )