Author: pramirez
Date: Mon Feb 27 17:45:24 2012
New Revision: 1294243

URL: http://svn.apache.org/viewvc?rev=1294243&view=rev
Log:
OODT-382 Lucene FileManager now initializes index in factory. 


Modified:
    
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalogFactory.java
    
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java

Modified: 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalogFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalogFactory.java?rev=1294243&r1=1294242&r2=1294243&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalogFactory.java
 (original)
+++ 
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalogFactory.java
 Mon Feb 27 17:45:24 2012
@@ -17,11 +17,19 @@
 
 package org.apache.oodt.cas.filemgr.catalog;
 
+//JDK imports
+import java.io.File;
+import java.util.logging.Logger;
+
 //OODT imports
 import org.apache.oodt.cas.filemgr.util.GenericFileManagerObjectFactory;
 import org.apache.oodt.cas.metadata.util.PathUtils;
 import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
 
+//Lucene imports
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.IndexWriter;
+
 /**
  * @author mattmann
  * @version $Revision$
@@ -51,6 +59,9 @@ public class LuceneCatalogFactory implem
        /* the merge factor */
        private int mergeFactor = -1;
        
+       /* our log stream */
+    private static final Logger LOG = 
Logger.getLogger(LuceneCatalogFactory.class.getName());
+    
        /**
         * 
         */
@@ -94,6 +105,24 @@ public class LuceneCatalogFactory implem
         * @see 
org.apache.oodt.cas.filemgr.catalog.CatalogFactory#createCatalog()
         */
        public Catalog createCatalog() {
+           File indexDir = new File(indexFilePath);
+           // Create the index if it does not already exist
+           IndexWriter writer = null;
+           if (!indexDir.exists()) {
+               try { 
+                   writer = new IndexWriter(indexDir, new StandardAnalyzer(), 
true);
+               } catch (Exception e) {
+                   LOG.severe("Unable to create index: " + e.getMessage());
+               } finally {
+                   if (writer != null) {
+                       try {
+                           writer.close();
+                       } catch (Exception e) {
+                           LOG.severe("Unable to close index: " + 
e.getMessage());
+                       }
+                   }
+               }
+           }
                return new LuceneCatalog(indexFilePath, validationLayer, 
pageSize,
                                commitLockTimeOut, writeLockTimeOut, 
mergeFactor);
        }

Modified: 
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java?rev=1294243&r1=1294242&r2=1294243&view=diff
==============================================================================
--- 
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
 (original)
+++ 
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
 Mon Feb 27 17:45:24 2012
@@ -156,6 +156,19 @@ public class TestLuceneCatalog extends T
         }
 
     }
+    
+    /**
+    * @since OODT-382
+    */
+    public void testNoCatalogDirectoryQueries() {
+        // Test querying against a catalog directory that has not yet been 
created or is empty. 
+        // The LuceneCatalogFactory should be creating the index directory if 
not there.
+        try {
+            myCat.getTopNProducts(10);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
 
     public void testRemoveProduct() {
         Product productToRemove = getTestProduct();


Reply via email to