From cefa85954d5018558706c7ecad9947fd0346d02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Osi=C5=84ski?= Date: Fri, 9 Dec 2011 16:04:58 +0000 Subject: [PATCH] SOLR-2942: ClassCastException when passing non-textual field for clustering git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1212495 13f79535-47bb-0310-9956-ffa450edef68 --- solr/contrib/clustering/CHANGES.txt | 3 +++ .../handler/clustering/carrot2/CarrotClusteringEngine.java | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/solr/contrib/clustering/CHANGES.txt b/solr/contrib/clustering/CHANGES.txt index 369e6295b14..1baee1dc05d 100644 --- a/solr/contrib/clustering/CHANGES.txt +++ b/solr/contrib/clustering/CHANGES.txt @@ -32,6 +32,9 @@ $Id$ * SOLR-2941: NullPointerException on clustering component initialization when schema does not have a unique key field (Stanislaw Osinski). +* SOLR-2942: ClassCastException when passing non-textual fields for + clustering (Stanislaw Osinski). + ================== Release 3.5.0 ================== (No Changes) diff --git a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java index 596d0f75337..57d2012dcf3 100644 --- a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java +++ b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java @@ -69,7 +69,6 @@ import org.carrot2.util.resource.ResourceLookup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -430,7 +429,7 @@ public class CarrotClusteringEngine extends SearchClusteringEngine { // Create a Carrot2 document Document carrotDocument = new Document(getConcatenated(sdoc, titleFieldSpec), - snippet, (String)sdoc.getFieldValue(urlField)); + snippet, ObjectUtils.toString(sdoc.getFieldValue(urlField), "")); // Store Solr id of the document, we need it to map document instances // found in clusters back to identifiers. @@ -510,7 +509,7 @@ public class CarrotClusteringEngine extends SearchClusteringEngine { // Join multiple values with a period so that Carrot2 does not pick up // phrases that cross field value boundaries (in most cases it would // create useless phrases). - result.append((String)ite.next()).append(" . "); + result.append(ObjectUtils.toString(ite.next())).append(" . "); } } return result.toString().trim();