Author: suat
Date: Mon Feb  4 09:54:40 2013
New Revision: 1442060

URL: http://svn.apache.org/viewvc?rev=1442060&view=rev
Log:
STANBOL-907: Applied Meric's patch which provides serialization of facets, in 
JSON format, included in the search results

Modified:
    
stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java

Modified: 
stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java?rev=1442060&r1=1442059&r2=1442060&view=diff
==============================================================================
--- 
stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java
 (original)
+++ 
stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java
 Mon Feb  4 09:54:40 2013
@@ -27,6 +27,7 @@ import java.util.Map.Entry;
 import org.apache.solr.client.solrj.response.FacetField;
 import org.apache.stanbol.contenthub.servicesapi.ldpath.LDProgramCollection;
 import 
org.apache.stanbol.contenthub.servicesapi.search.featured.DocumentResult;
+import org.apache.stanbol.contenthub.servicesapi.search.featured.FacetResult;
 import org.apache.stanbol.contenthub.servicesapi.search.featured.SearchResult;
 import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeyword;
 import org.codehaus.jettison.json.JSONArray;
@@ -134,12 +135,23 @@ public class JSONUtils {
                     jArr.put(toJSON((FacetField.Count) element));
                 } else if 
(RelatedKeyword.class.isAssignableFrom(element.getClass())) {
                     jArr.put(toJSON((RelatedKeyword) element));
+                } else if 
(FacetResult.class.isAssignableFrom(element.getClass())) {
+                       jArr.put(toJSON((FacetResult) element));
                 }
             }
         }
         return jArr;
     }
 
+    private static JSONObject toJSON(FacetResult facetResult) throws 
JSONException {
+        JSONObject jObj = new JSONObject();
+        if (facetResult != null) {
+            jObj.put("facet", toJSON(facetResult.getFacetField()));
+            jObj.put("type", facetResult.getType());
+        }
+        return jObj;
+    }
+    
     private static JSONObject toJSON(RelatedKeyword relatedKeyword) throws 
JSONException {
         JSONObject jObj = new JSONObject();
         if (relatedKeyword != null) {


Reply via email to