Author: hardy.ferentschik
Date: 2007-07-24 05:47:52 -0400 (Tue, 24 Jul 2007)
New Revision: 12804
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/store/DirectoryProviderFactory.java
Log:
HSEARCH-67.
Added code to retrieve the lucene indexing parameters from the configuration.
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/store/DirectoryProviderFactory.java 2007-07-24
09:45:37 UTC (rev 12803)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/store/DirectoryProviderFactory.java 2007-07-24
09:47:52 UTC (rev 12804)
@@ -9,6 +9,7 @@
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.backend.LuceneIndexingParameters;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.store.optimization.OptimizerStrategy;
@@ -24,10 +25,12 @@
* Create a Lucene directory provider
* <p/>
* Lucene directory providers are configured through properties
- * - hibernate.search.default.* and
- * - hibernate.search.<indexname>.*
+ * <ul>
+ * <li>hibernate.search.default.* and</li>
+ * <li>hibernate.search.<indexname>.*</li>
+ * </ul>
* <p/>
- * <indexname> properties have precedence over default
+ * <indexname> properties have precedence over default
* <p/>
* The implementation is described by
* hibernate.search.[default|indexname].directory_provider
@@ -36,12 +39,21 @@
*
* @author Emmanuel Bernard
* @author Sylvain Vieujot
+ * @author Hardy Ferentschik
*/
public class DirectoryProviderFactory {
public List<DirectoryProvider<?>> providers = new
ArrayList<DirectoryProvider<?>>();
private static String LUCENE_PREFIX = "hibernate.search.";
private static String LUCENE_DEFAULT = LUCENE_PREFIX + "default.";
private static String DEFAULT_DIRECTORY_PROVIDER = FSDirectoryProvider.class.getName();
+
+ // Lucene index performance paramters
+ private static final String MERGE_FACTOR = "merge_factor";
+ private static final String MAX_MERGE_DOCS = "max_merge_docs";
+ private static final String MAX_BUFFERED_DOCS = "max_buffered_docs";
+ private static final String BATCH_MERGE_FACTOR = "merge_factor.batch";
+ private static final String BATCH_MAX_MERGE_DOCS = "max_merge_docs.batch";
+ private static final String BATCH_MAX_BUFFERED_DOCS =
"max_buffered_docs.batch";
//TODO for the public?
public DirectoryProvider<?> createDirectoryProvider(XClass entity, Configuration
cfg, SearchFactoryImplementor searchFactoryImplementor) {
@@ -77,22 +89,105 @@
return providers.get( index );
}
else {
- boolean incremental = indexProps.containsKey(
"optimizer.operation_limit.max" )
- || indexProps.containsKey( "optimizer.transaction_limit.max" );
- OptimizerStrategy optimizerStrategy;
- if (incremental) {
- optimizerStrategy = new IncrementalOptimizerStrategy();
- optimizerStrategy.initialize( provider, indexProps, searchFactoryImplementor);
- }
- else {
- optimizerStrategy = new NoOpOptimizerStrategy();
- }
- searchFactoryImplementor.addOptimizerStrategy(provider, optimizerStrategy);
+ configureOptimizerStrategy(searchFactoryImplementor, indexProps, provider);
+ configureIndexingParameters(searchFactoryImplementor, indexProps, provider);
providers.add( provider );
return provider;
}
}
+ private void configureOptimizerStrategy(SearchFactoryImplementor
searchFactoryImplementor, Properties indexProps, DirectoryProvider<?> provider) {
+ boolean incremental = indexProps.containsKey( "optimizer.operation_limit.max"
)
+ || indexProps.containsKey( "optimizer.transaction_limit.max" );
+ OptimizerStrategy optimizerStrategy;
+ if (incremental) {
+ optimizerStrategy = new IncrementalOptimizerStrategy();
+ optimizerStrategy.initialize( provider, indexProps, searchFactoryImplementor);
+ }
+ else {
+ optimizerStrategy = new NoOpOptimizerStrategy();
+ }
+ searchFactoryImplementor.addOptimizerStrategy(provider, optimizerStrategy);
+ }
+
+ /**
+ * Creates a new <code>LuceneIndexingParameters</code> instance for the
specified provider.
+ * If there are no matching properties in the configuration default values will be
applied.
+ * <p>
+ * NOTE:</br>
+ * If a non batch value is set in the configuration apply it also to the
+ * batch mode. This covers the case where users only specify
+ * paramters for the non batch mode. In this case the same parameters apply for
+ * batch indexing.
+ * </p>
+ *
+ * @param searchFactoryImplementor the search factory.
+ * @param indexProps The properties extracted from the configuration.
+ * @param provider The direcotry provider for which to configure the indexing
parameters.
+ */
+ private void configureIndexingParameters(SearchFactoryImplementor
searchFactoryImplementor, Properties indexProps, DirectoryProvider<?> provider) {
+
+ LuceneIndexingParameters indexingParams = new LuceneIndexingParameters();
+ String s = indexProps.getProperty(MERGE_FACTOR);
+
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setMergeFactor(Integer.valueOf(s));
+ indexingParams.setBatchMergeFactor(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + MERGE_FACTOR + ":
" + s);
+ }
+ }
+
+ s = indexProps.getProperty(MAX_MERGE_DOCS);
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setMaxMergeDocs(Integer.valueOf(s));
+ indexingParams.setBatchMaxMergeDocs(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + MAX_MERGE_DOCS +
": " + s);
+ }
+ }
+
+ s = indexProps.getProperty(MAX_BUFFERED_DOCS);
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setMaxBufferedDocs(Integer.valueOf(s));
+ indexingParams.setBatchMaxBufferedDocs(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + MAX_BUFFERED_DOCS +
": " + s);
+ }
+ }
+
+ s = indexProps.getProperty(BATCH_MERGE_FACTOR);
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setBatchMergeFactor(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + BATCH_MERGE_FACTOR +
": " + s);
+ }
+ }
+
+ s = indexProps.getProperty(BATCH_MAX_MERGE_DOCS);
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setBatchMaxMergeDocs(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + BATCH_MAX_MERGE_DOCS +
": " + s);
+ }
+ }
+
+ s = indexProps.getProperty(BATCH_MAX_BUFFERED_DOCS);
+ if (!StringHelper.isEmpty( s )) {
+ try{
+ indexingParams.setBatchMaxBufferedDocs(Integer.valueOf(s));
+ } catch (NumberFormatException ne) {
+ throw new HibernateException("Invalid value for " + BATCH_MAX_BUFFERED_DOCS
+ ": " + s);
+ }
+ }
+ searchFactoryImplementor.addIndexingParmeters(provider, indexingParams);
+ }
+
private static Properties getDirectoryProperties(Configuration cfg, String
directoryProviderName) {
Properties props = cfg.getProperties();
String indexName = LUCENE_PREFIX + directoryProviderName;
@@ -133,7 +228,7 @@
pc = pc.getSuperclass();
}
while ( pc != null );
- //there is nobody outthere with a non default @Indexed.index
+ //there is nobody out there with a non default @Indexed.index
if ( rootIndex != null ) {
return rootIndex.getName();
}
Show replies by date