You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/12/13 17:04:04 UTC

svn commit: r1421355 - /stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java

Author: suat
Date: Thu Dec 13 16:04:03 2012
New Revision: 1421355

URL: http://svn.apache.org/viewvc?rev=1421355&view=rev
Log:
Fix for STANBOL-782.

It is not mandatory for a ContentItem to have a textual content part i.e a content part having one of the TEXT_HTML, TEXT_PLAIN or TEXT_XML media types. If it has a binary content only the binary content of the ContentItem is stored but not indexed. A StoreException is thrown only if the ContentItem does have neither a textual content part or any binary content.

Modified:
    stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java

Modified: stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java?rev=1421355&r1=1421354&r2=1421355&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java (original)
+++ stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java Thu Dec 13 16:04:03 2012
@@ -18,6 +18,7 @@
 package org.apache.stanbol.contenthub.store.solr;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -288,31 +289,31 @@ public class SolrStoreImpl implements So
         enhance(ci, chain);
         return put(ci, ldProgramName);
     }
-    
+
     /**
      * Put the ContentItem into the default Solr core
      */
     @Override
     public String put(ContentItem ci) throws StoreException {
-    	return put(ci,null);
+        return put(ci, null);
     }
 
     /**
-     * Put the ContentItem into the Solr core identify by ldProgramName. If ldProgramName is null, put the CI to the default Solr core.
-     * Also save the ContentItem enhancements in the EnhancementGraph
+     * Put the ContentItem into the Solr core identify by ldProgramName. If ldProgramName is null, put the CI
+     * to the default Solr core. Also save the ContentItem enhancements in the EnhancementGraph
      */
     @Override
     public String put(ContentItem ci, String ldProgramName) throws StoreException {
-    	SolrInputDocument doc = new SolrInputDocument();
+        SolrInputDocument doc = new SolrInputDocument();
         addDefaultFields(ci, doc);
         SolrServer solrServer;
         if (ldProgramName == null || ldProgramName.isEmpty()
             || ldProgramName.equals(SolrCoreManager.CONTENTHUB_DEFAULT_INDEX_NAME)) {
-        	
-        	addSolrSpecificFields(ci, doc);
-        	solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer();
-        }else{
-        	addSolrSpecificFields(ci, doc, ldProgramName);
+
+            addSolrSpecificFields(ci, doc);
+            solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer();
+        } else {
+            addSolrSpecificFields(ci, doc, ldProgramName);
             solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
                 ldProgramName);
         }
@@ -338,7 +339,8 @@ public class SolrStoreImpl implements So
                     "ID of the content item cannot be null while inserting to the SolrStore.");
         }
 
-        String content = null;
+        // get content
+        String content = "";
         Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES);
         if (contentPart != null) {
             try {
@@ -348,20 +350,26 @@ public class SolrStoreImpl implements So
                 log.error(msg, ex);
                 throw new StoreException(msg, ex);
             }
-            doc.addField(SolrFieldName.CONTENT.toString(), content);
-        } 
+        }
+        InputStream binaryContent = ci.getStream();
 
-        Calendar cal = Calendar.getInstance();
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-        String creationDate = sdf.format(cal.getTime());
+        if (content.equals("") && binaryContent == null) {
+            throw new StoreException("No textual or binary content for the ContentItem");
+        }
 
-        doc.addField(SolrFieldName.ID.toString(), ci.getUri().getUnicodeString());
         try {
-            doc.addField(SolrFieldName.BINARYCONTENT.toString(), IOUtils.toByteArray(ci.getStream()));
+            doc.addField(SolrFieldName.CONTENT.toString(), content);
+            doc.addField(SolrFieldName.BINARYCONTENT.toString(), IOUtils.toByteArray(binaryContent));
         } catch (IOException e) {
             throw new StoreException("Failed to get bytes of conten item stream", e);
         }
+
+        doc.addField(SolrFieldName.ID.toString(), ci.getUri().getUnicodeString());
         doc.addField(SolrFieldName.MIMETYPE.toString(), ci.getMimeType());
+
+        Calendar cal = Calendar.getInstance();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+        String creationDate = sdf.format(cal.getTime());
         doc.addField(SolrFieldName.CREATIONDATE.toString(), creationDate);
 
         // add the number of enhancemets to the content item