You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/08/22 12:16:53 UTC

svn commit: r1375970 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/search/ applications/content/webapp/content/WEB-INF/actions/cms/ specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/

Author: jacopoc
Date: Wed Aug 22 10:16:52 2012
New Revision: 1375970

URL: http://svn.apache.org/viewvc?rev=1375970&view=rev
Log:
Misc cleanups (no functional changes) to the Lucene integration:
* removed unused imports
* removed unused old methods with duplicated logic
* made some methods private
* improved some debug statements
* formatting adjustments

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java
    ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy
    ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java?rev=1375970&r1=1375969&r2=1375970&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java Wed Aug 22 10:16:52 2012
@@ -19,7 +19,6 @@
 package org.ofbiz.content.search;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.util.List;
 import java.util.Map;
 
@@ -50,7 +49,6 @@ import org.apache.lucene.store.FSDirecto
 import org.apache.lucene.util.Version;
 
 
-
 /**
  * SearchWorker Class
  */
@@ -76,7 +74,7 @@ public class SearchWorker {
                     for (GenericValue subContent : subContentList) {
                         contentIdList.add(subContent.getString("contentId"));
                     }
-                    indexContentList(contentIdList, delegator, dispatcher, context);
+                    indexContentList(dispatcher, delegator, context, contentIdList, null);
                     indexTree(dispatcher, delegator, siteContentId, context, path);
                 } else {
                     List<String> badIndexList = UtilGenerics.checkList(context.get("badIndexList"));
@@ -93,13 +91,17 @@ public class SearchWorker {
         return results;
     }
 
-    public static void indexContentList(List<String> idList, Delegator delegator, LocalDispatcher dispatcher, Map<String, Object> context) throws Exception {
-        indexContentList(dispatcher, delegator, context, idList, null);
+    public static String getIndexPath(String path) {
+        String indexAllPath = path;
+        if (UtilValidate.isEmpty(indexAllPath)) {
+            indexAllPath = UtilProperties.getPropertyValue("search", "defaultIndex", "index");
+        }
+        return indexAllPath;
     }
 
-    public static void indexContentList(LocalDispatcher dispatcher, Delegator delegator, Map<String, Object> context, List<String> idList, String path) throws Exception {
+    private static void indexContentList(LocalDispatcher dispatcher, Delegator delegator, Map<String, Object> context, List<String> idList, String path) throws Exception {
         Directory directory = FSDirectory.open(new File(getIndexPath(path)));
-        if (Debug.infoOn()) Debug.logInfo("in indexContent, indexAllPath: " + directory.toString(), module);
+        if (Debug.infoOn()) Debug.logInfo("in indexContentList, indexAllPath: " + directory.toString(), module);
         // Delete existing documents
         IndexReader reader = null;
         try {
@@ -109,12 +111,12 @@ public class SearchWorker {
         }
         List<GenericValue> contentList = FastList.newInstance();
         for (String id : idList) {
-            if (Debug.infoOn()) Debug.logInfo("in indexContent, id:" + id, module);
+            if (Debug.infoOn()) Debug.logInfo("in indexContentList, id:" + id, module);
             try {
                 GenericValue content = delegator.findOne("Content", UtilMisc .toMap("contentId", id), true);
                 if (content != null) {
                     if (reader != null) {
-                        deleteContentDocument(content, reader);
+                        deleteContentDocuments(content, reader);
                     }
                     contentList.add(content);
                 }
@@ -146,62 +148,23 @@ public class SearchWorker {
         writer.close();
     }
 
-    public static void deleteContentDocument(GenericValue content, String path) throws Exception {
-        Directory directory = FSDirectory.open(new File(getIndexPath(path)));
-        IndexReader reader = IndexReader.open(directory);
-        deleteContentDocument(content, reader);
-        reader.close();
-    }
-
-    public static void deleteContentDocument(GenericValue content, IndexReader reader) throws Exception {
+    private static void deleteContentDocuments(GenericValue content, IndexReader reader) throws Exception {
         String contentId = content.getString("contentId");
         Term term = new Term("contentId", contentId);
-        if (Debug.infoOn()) Debug.logInfo("in indexContent, term:" + term, module);
-        int qtyDeleted = reader.deleteDocuments(term);
-        if (Debug.infoOn()) Debug.logInfo("in indexContent, qtyDeleted:" + qtyDeleted, module);
+        deleteDocumentsByTerm(term, reader);
         String dataResourceId = content.getString("dataResourceId");
         if (dataResourceId != null) {
-            deleteDataResourceDocument(dataResourceId, reader);
+            term = new Term("dataResourceId", dataResourceId);
+            deleteDocumentsByTerm(term, reader);
         }
     }
 
-    public static void deleteDataResourceDocument(String dataResourceId, IndexReader reader) throws Exception {
-        Term term = new Term("dataResourceId", dataResourceId);
-        if (Debug.infoOn()) Debug.logInfo("in indexContent, term:" + term, module);
+    private static void deleteDocumentsByTerm(Term term, IndexReader reader) throws Exception {
         int qtyDeleted = reader.deleteDocuments(term);
-        if (Debug.infoOn()) Debug.logInfo("in indexContent, qtyDeleted:" + qtyDeleted, module);
-    }
-
-    public static void indexContent(LocalDispatcher dispatcher, Delegator delegator, Map<String, Object> context, GenericValue content, String path) throws Exception {
-        Directory directory = FSDirectory.open(new File(getIndexPath(path)));
-        long savedWriteLockTimeout = IndexWriterConfig.getDefaultWriteLockTimeout();
-        Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
-        IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer);
-        IndexWriter writer = null;
-        try {
-            try {
-                IndexWriterConfig.setDefaultWriteLockTimeout(2000);
-                writer  = new IndexWriter(directory, conf);
-            } finally {
-                IndexWriterConfig.setDefaultWriteLockTimeout(savedWriteLockTimeout);
-            }
-            if (Debug.infoOn()) Debug.logInfo("Used old directory:" + directory.toString(), module);
-        } catch (FileNotFoundException e) {
-            try {
-                IndexWriterConfig.setDefaultWriteLockTimeout(2000);
-                writer  = new IndexWriter(directory, conf);
-            } finally {
-                IndexWriterConfig.setDefaultWriteLockTimeout(savedWriteLockTimeout);
-            }
-            if (Debug.infoOn()) Debug.logInfo("Created new directory:" + directory.toString(), module);
-        }
-
-        indexContent(dispatcher, delegator, context, content, writer);
-        writer.forceMerge(1);
-        writer.close();
+        if (Debug.infoOn()) Debug.logInfo("Deleted " + qtyDeleted + "documents for term: " + term, module);
     }
 
-    public static void indexContent(LocalDispatcher dispatcher, Delegator delegator, Map<String, Object> context, GenericValue content, IndexWriter writer) throws Exception {
+    private static void indexContent(LocalDispatcher dispatcher, Delegator delegator, Map<String, Object> context, GenericValue content, IndexWriter writer) throws Exception {
         Document doc = ContentDocument.Document(content, context, dispatcher);
 
         if (doc != null) {
@@ -213,44 +176,10 @@ public class SearchWorker {
         /*
             String dataResourceId = content.getString("dataResourceId");
             if (UtilValidate.isNotEmpty(dataResourceId)) {
-                indexDataResource(delegator, context, dataResourceId, writer);
+                doc = DataResourceDocument.Document(dataResourceId, delegator, context);
+                writer.addDocument(doc);
             }
          */
     }
 
-    public static void indexDataResource(Delegator delegator, Map<String, Object> context, String id) throws Exception {
-        String path = null;
-        indexDataResource(delegator, context, id, path);
-    }
-
-    public static void indexDataResource(Delegator delegator, Map<String, Object> context, String id, String path) throws Exception {
-        Directory directory = FSDirectory.open(new File(getIndexPath(path)));
-        long savedWriteLockTimeout = IndexWriterConfig.getDefaultWriteLockTimeout();
-        Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
-        IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer);
-        IndexWriter writer = null;
-
-        try {
-            IndexWriterConfig.setDefaultWriteLockTimeout(2000);
-            writer  = new IndexWriter(directory, conf);
-        } finally {
-            IndexWriterConfig.setDefaultWriteLockTimeout(savedWriteLockTimeout);
-        }
-        indexDataResource(delegator, context, id, writer);
-        writer.forceMerge(1);
-        writer.close();
-    }
-
-    public static void indexDataResource(Delegator delegator, Map<String, Object> context, String id, IndexWriter writer) throws Exception {
-        Document doc = DataResourceDocument.Document(id, delegator, context);
-        writer.addDocument(doc);
-    }
-
-    public static String getIndexPath(String path) {
-        String indexAllPath = path;
-        if (UtilValidate.isEmpty(indexAllPath)) {
-            indexAllPath = UtilProperties.getPropertyValue("search", "defaultIndex", "index");
-        }
-        return indexAllPath;
-    }
 }

Modified: ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy?rev=1375970&r1=1375969&r2=1375970&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy (original)
+++ ofbiz/trunk/applications/content/webapp/content/WEB-INF/actions/cms/Search.groovy Wed Aug 22 10:16:52 2012
@@ -24,7 +24,6 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.Term
 import org.apache.lucene.queryParser.QueryParser
 import org.apache.lucene.store.FSDirectory
-import org.apache.lucene.util.Version
 import org.ofbiz.base.util.Debug
 import org.ofbiz.base.util.UtilHttp
 import org.ofbiz.content.search.SearchWorker

Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy?rev=1375970&r1=1375969&r2=1375970&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/actions/content/Search.groovy Wed Aug 22 10:16:52 2012
@@ -24,7 +24,6 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.Term
 import org.apache.lucene.queryParser.QueryParser
 import org.apache.lucene.store.FSDirectory
-import org.apache.lucene.util.Version
 import org.ofbiz.base.util.Debug
 import org.ofbiz.base.util.UtilHttp
 import org.ofbiz.content.search.SearchWorker