Author: erwan
Date: Tue Sep 4 21:26:41 2012
New Revision: 1380896
URL: http://svn.apache.org/viewvc?rev=1380896&view=rev
Log:
Upgrading to lucene 3.6.1
Added:
ofbiz/trunk/applications/content/lib/lucene-core-3.6.1.jar (with props)
Removed:
ofbiz/trunk/applications/content/lib/lucene-core-3.5.0.jar
Modified:
ofbiz/trunk/.classpath
ofbiz/trunk/LICENSE
ofbiz/trunk/applications/content/src/org/ofbiz/content/search/SearchWorker.java
ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java
Modified: ofbiz/trunk/.classpath
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/.classpath?rev=1380896&r1=1380895&r2=1380896&view=diff
==============================================================================
--- ofbiz/trunk/.classpath (original)
+++ ofbiz/trunk/.classpath Tue Sep 4 21:26:41 2012
@@ -4,7 +4,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib"
path="applications/content/lib/fontbox-1.4.0.jar"/>
<classpathentry kind="lib"
path="applications/content/lib/jempbox-1.4.0.jar"/>
- <classpathentry kind="lib"
path="applications/content/lib/lucene-core-3.5.0.jar"/>
+ <classpathentry kind="lib"
path="applications/content/lib/lucene-core-3.6.1.jar"/>
<classpathentry kind="lib"
path="applications/content/lib/pdfbox-1.4.0.jar"/>
<classpathentry kind="lib"
path="applications/content/lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib"
path="applications/content/lib/poi-3.8-20120326.jar"/>
Modified: ofbiz/trunk/LICENSE
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=1380896&r1=1380895&r2=1380896&view=diff
==============================================================================
--- ofbiz/trunk/LICENSE (original)
+++ ofbiz/trunk/LICENSE Tue Sep 4 21:26:41 2012
@@ -104,7 +104,7 @@ ofbiz/trunk/framework/geronimo/lib/geron
ofbiz/trunk/framework/geronimo/lib/geronimo-transaction-2.1.1.jar
ofbiz/trunk/applications/content/lib/fontbox-1.4.0.jar
ofbiz/trunk/applications/content/lib/jempbox-1.4.0.jar
-ofbiz/trunk/applications/content/lib/lucene-core-3.5.0.jar
+ofbiz/trunk/applications/content/lib/lucene-core-3.6.1.jar
ofbiz/trunk/applications/content/lib/pdfbox-1.4.0.jar
ofbiz/trunk/applications/content/lib/poi-3.8-20120326.jar
ofbiz/trunk/applications/content/lib/poi-ooxml-3.8-20120326.jar
Added: ofbiz/trunk/applications/content/lib/lucene-core-3.6.1.jar
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/lib/lucene-core-3.6.1.jar?rev=1380896&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/applications/content/lib/lucene-core-3.6.1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
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=1380896&r1=1380895&r2=1380896&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
Tue Sep 4 21:26:41 2012
@@ -19,12 +19,14 @@
package org.ofbiz.content.search;
import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
import javolution.util.FastList;
import javolution.util.FastMap;
+import org.apache.lucene.index.*;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilGenerics;
@@ -40,15 +42,11 @@ import org.ofbiz.service.LocalDispatcher
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.Version;
-
/**
* SearchWorker Class
*/
@@ -56,7 +54,7 @@ public class SearchWorker {
public static final String module = SearchWorker.class.getName();
- public static final Version LUCENE_VERSION = Version.LUCENE_35;
+ public static final Version LUCENE_VERSION = Version.LUCENE_36;
public static Map<String, Object> indexTree(LocalDispatcher dispatcher,
Delegator delegator, String siteId, Map<String, Object> context, String path)
throws Exception {
Map<String, Object> results = FastMap.newInstance();
@@ -99,24 +97,39 @@ public class SearchWorker {
return indexAllPath;
}
- private static void indexContentList(LocalDispatcher dispatcher, Delegator
delegator, Map<String, Object> context, List<String> idList, String path)
throws Exception {
+ private static IndexWriter getDefaultIndexWriter(Directory directory) {
+ IndexWriter writer = null;
+ long savedWriteLockTimeout =
IndexWriterConfig.getDefaultWriteLockTimeout();
+ Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
+ IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION,
analyzer);
+ IndexWriterConfig.setDefaultWriteLockTimeout(2000);
+ try {
+ writer = new IndexWriter(directory, conf);
+ } catch (CorruptIndexException e) {
+ Debug.logError("Corrupted lucene index: " + e.getMessage(),
module);
+ } catch (LockObtainFailedException e) {
+ Debug.logError("Could not obtain Lock on lucene index " +
e.getMessage(), module);
+ } catch (IOException e) {
+ Debug.logError(e.getMessage(), module);
+ } finally {
+
IndexWriterConfig.setDefaultWriteLockTimeout(savedWriteLockTimeout);
+ }
+ return writer;
+ }
+
+ public 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 indexContentList, indexAllPath:
" + directory.toString(), module);
// Delete existing documents
- IndexReader reader = null;
- try {
- reader = IndexReader.open(directory, false);
- } catch (Exception e) {
- // ignore
- }
+ IndexWriter writer = getDefaultIndexWriter(directory);
List<GenericValue> contentList = FastList.newInstance();
for (String id : idList) {
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) {
- deleteContentDocuments(content, reader);
+ if (writer != null) {
+ deleteContentDocuments(content, writer);
}
contentList.add(content);
}
@@ -125,43 +138,39 @@ public class SearchWorker {
return;
}
}
- if (reader != null) {
- reader.close();
- }
- // Now create
- IndexWriter writer = null;
- long savedWriteLockTimeout =
IndexWriterConfig.getDefaultWriteLockTimeout();
- Analyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
- IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION,
analyzer);
-
- try {
- IndexWriterConfig.setDefaultWriteLockTimeout(2000);
- writer = new IndexWriter(directory, conf);
- } finally {
-
IndexWriterConfig.setDefaultWriteLockTimeout(savedWriteLockTimeout);
- }
-
for (GenericValue gv : contentList) {
indexContent(dispatcher, delegator, context, gv, writer);
}
- writer.forceMerge(1);
+ try {
+ writer.forceMerge(1);
+ } catch (NullPointerException e) {
+ Debug.logError(e, module);
+ }
writer.close();
}
- private static void deleteContentDocuments(GenericValue content,
IndexReader reader) throws Exception {
+ private static void deleteContentDocuments(GenericValue content,
IndexWriter writer) throws Exception {
String contentId = content.getString("contentId");
Term term = new Term("contentId", contentId);
- deleteDocumentsByTerm(term, reader);
+ deleteDocumentsByTerm(term, writer);
String dataResourceId = content.getString("dataResourceId");
if (dataResourceId != null) {
term = new Term("dataResourceId", dataResourceId);
- deleteDocumentsByTerm(term, reader);
+ deleteDocumentsByTerm(term, writer);
}
}
- private static void deleteDocumentsByTerm(Term term, IndexReader reader)
throws Exception {
- int qtyDeleted = reader.deleteDocuments(term);
- if (Debug.infoOn()) Debug.logInfo("Deleted " + qtyDeleted + "documents
for term: " + term, module);
+ private static void deleteDocumentsByTerm(Term term, IndexWriter writer)
throws Exception {
+ IndexReader reader = IndexReader.open(writer, false);
+ int qtyBefore = reader.docFreq(term);
+
+ //deletes documents, all the rest is for logging
+ writer.deleteDocuments(term);
+
+ int qtyAfter = reader.docFreq(term);
+ reader.close();
+
+ if (Debug.infoOn()) Debug.logInfo("For term " + term.toString() + ",
documents deleted: " + qtyBefore + ", remaining: " + qtyAfter, module);
}
private static void indexContent(LocalDispatcher dispatcher, Delegator
delegator, Map<String, Object> context, GenericValue content, IndexWriter
writer) throws Exception {
Modified:
ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java?rev=1380896&r1=1380895&r2=1380896&view=diff
==============================================================================
---
ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java
(original)
+++
ofbiz/trunk/applications/content/src/org/ofbiz/content/test/LuceneTests.java
Tue Sep 4 21:26:41 2012
@@ -36,7 +36,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.Version;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.content.search.SearchWorker;
@@ -76,7 +75,7 @@ public class LuceneTests extends OFBizTe
Directory directory = FSDirectory.open(new
File(SearchWorker.getIndexPath(null)));
IndexReader r = null;
try {
- r = IndexReader.open(directory, false);
+ r = IndexReader.open(directory);
} catch (Exception e) {
// ignore
}