You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ri...@apache.org on 2013/01/31 03:19:43 UTC

svn commit: r1440797 - /oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java

Author: riverma
Date: Thu Jan 31 02:19:43 2013
New Revision: 1440797

URL: http://svn.apache.org/viewvc?rev=1440797&view=rev
Log:
OODT-556 resolution: Add ability to delete a product from Solr index via SolrIndexer tool

Modified:
    oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java

Modified: oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java?rev=1440797&r1=1440796&r2=1440797&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java (original)
+++ oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java Thu Jan 31 02:19:43 2013
@@ -485,6 +485,45 @@ public class SolrIndexer {
 	}
 
 	/**
+	 * This method deletes a single product identified by a productID from the Solr index
+	 * 
+	 * @param productId
+	 * @throws IOException
+	 * @throws SolrServerException
+	 */
+	public void deleteProduct(String productId) throws IOException, SolrServerException {
+		LOG.info("Attempting to delete product: " + productId);
+		this.deleteProductFromIndex(productId);
+	}
+
+	/**
+	 * This method deletes a product(s) from the Solr index identified by a given name
+	 * 
+	 * @param productName
+	 * @throws IOException
+	 * @throws SolrServerException
+	 */
+	public void deleteProductByName(String productName) throws IOException, SolrServerException {
+		LOG.info("Attempting to delete product: " + productName);
+
+		try {
+			String productNameField = config.mapProperties.getProperty(PRODUCT_NAME);
+			if (StringUtils.hasText(productNameField)) {
+				server.deleteByQuery(productNameField+":"+productName);
+			} else {
+				LOG.warning("Metadata field "+PRODUCT_NAME+" is not mapped to any Solr field, cannot delete product by name");
+			}
+		} catch(Exception e) {
+			LOG.warning("Could not delete product: "+productName+" from Solr index");
+		}
+
+	}
+
+	private void deleteProductFromIndex(String productId) throws IOException, SolrServerException {
+		server.deleteById(productId);
+	}
+	
+	/**
 	 * Quick helper method to do substitution on the keys specified in the config
 	 * 
 	 * @param metadata