[exo-jcr-commits] exo-jcr SVN: r4716 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene: spell and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Aug 9 07:34:25 EDT 2011
Author: nzamosenchuk
Date: 2011-08-09 07:34:25 -0400 (Tue, 09 Aug 2011)
New Revision: 4716
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/DirectoryManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/spell/LuceneSpellChecker.java
Log:
EXOJCR-1437 : allow to set custom Directory and LockFactory implementation class.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/DirectoryManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/DirectoryManager.java 2011-08-09 11:33:10 UTC (rev 4715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/DirectoryManager.java 2011-08-09 11:34:25 UTC (rev 4716)
@@ -17,7 +17,6 @@
package org.exoplatform.services.jcr.impl.core.query.lucene.directory;
import org.apache.lucene.store.Directory;
-import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
import java.io.IOException;
@@ -28,12 +27,6 @@
*/
public interface DirectoryManager {
- /**
- * The full qualified name of the lock factory to use by default, if not
- * specified org.apache.lucene.store.NativeFSLockFactory will be used
- */
- public static final String LOCK_FACTORY_CLASS = PropertyManager
- .getProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass");
/**
* Initializes the directory manager with a reference to the search index.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java 2011-08-09 11:33:10 UTC (rev 4715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java 2011-08-09 11:34:25 UTC (rev 4716)
@@ -19,8 +19,8 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.NativeFSLockFactory;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
import java.io.File;
@@ -37,6 +37,41 @@
{
/**
+ * The full qualified name of the lock factory to use by default, if not
+ * specified org.apache.lucene.store.NativeFSLockFactory will be used
+ */
+ public static final String LOCK_FACTORY_CLASS;
+
+ /**
+ * The full qualified name of the lock factory to use by default, if not
+ * specified org.apache.lucene.store.NativeFSLockFactory will be used
+ */
+ public static final String FS_DIRECTORY_CLASS;
+
+ /**
+ * Static block, used to initialize (map) org.exoplatform.jcr.lucene*
+ * properties to org.apache.lucene.* and make it only once at a system
+ * start
+ *
+ * Required to set custom Index Directory and Lock Factory implementations for Lucene 2.x.
+ */
+ static
+ {
+ // get eXo system properties
+ LOCK_FACTORY_CLASS = PropertyManager.getProperty("org.exoplatform.jcr.lucene.store.FSDirectoryLockFactoryClass");
+ FS_DIRECTORY_CLASS = PropertyManager.getProperty("org.exoplatform.jcr.lucene.FSDirectory.class");
+ // map to Lucene ones. Works only with Lucene 2.x.
+ if (LOCK_FACTORY_CLASS != null)
+ {
+ PropertyManager.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass", LOCK_FACTORY_CLASS);
+ }
+ if (FS_DIRECTORY_CLASS != null)
+ {
+ PropertyManager.setProperty("org.apache.lucene.FSDirectory.class", FS_DIRECTORY_CLASS);
+ }
+ }
+
+ /**
* The base directory.
*/
private File baseDir;
@@ -81,7 +116,7 @@
public Directory run() throws Exception
{
File dir;
- if (name.equals("."))
+ if (name.equals("."))
{
dir = baseDir;
}
@@ -97,7 +132,16 @@
throw new IOException("Cannot create directory: " + dir);
}
}
- return FSDirectory.getDirectory(dir, LOCK_FACTORY_CLASS != null ? null : new NativeFSLockFactory(dir));
+ // if both not defined, using FSDirectory.open
+ if (FS_DIRECTORY_CLASS == null && LOCK_FACTORY_CLASS == null)
+ {
+ return FSDirectory.open(dir, new NativeFSLockFactory(dir));
+ }
+ // LOCK FACTORY only defined, using deprecated getDirectory method
+ else
+ {
+ return FSDirectory.getDirectory(dir, LOCK_FACTORY_CLASS != null ? null : new NativeFSLockFactory(dir));
+ }
}
});
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/spell/LuceneSpellChecker.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/spell/LuceneSpellChecker.java 2011-08-09 11:33:10 UTC (rev 4715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/spell/LuceneSpellChecker.java 2011-08-09 11:34:25 UTC (rev 4716)
@@ -250,7 +250,7 @@
* @param morePopular
* return only the suggest words that are as frequent or more frequent than the searched word
*/
- InternalSpellChecker(SearchIndex handler, float minDistance, boolean morePopular) throws IOException
+ InternalSpellChecker(final SearchIndex handler, float minDistance, boolean morePopular) throws IOException
{
this.handler = handler;
final String path = handler.getContext().getIndexDirectory() + File.separatorChar + "spellchecker";
@@ -259,9 +259,8 @@
{
public Object run() throws Exception
{
- spellIndexDirectory =
- FSDirectory.getDirectory(path, DirectoryManager.LOCK_FACTORY_CLASS != null ? null
- : new NativeFSLockFactory(path));
+ spellIndexDirectory = handler.getDirectoryManager().getDirectory(path);
+
if (IndexReader.indexExists(spellIndexDirectory))
{
lastRefresh = System.currentTimeMillis();
More information about the exo-jcr-commits
mailing list