Skip to content

Apache Lucene open-source search software

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

Ryan McKinley054df4343c79
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<NamedList<Object>> values = new ArrayList<NamedList<Object>>( superFacets.size() );
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
- if (kv.getValue() > minMatch ) {
+ if (kv.getValue() > minMatch ) {
+ String internal = ftype.toInternal( kv.getKey() );
+ f.setValue( internal );
+
SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>();
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 )