Author: sannegrinovero
Date: 2008-09-05 11:26:25 -0400 (Fri, 05 Sep 2008)
New Revision: 15155
Modified:
search/trunk/doc/reference/en/modules/configuration.xml
search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java
search/trunk/src/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java
search/trunk/src/java/org/hibernate/search/backend/configuration/IndexWriterSetting.java
search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationParseHelperTest.java
search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
Log:
HSEARCH-258 : Add configuration option for Lucene's UseCompoundFile to IndexWriter
settings
Modified: search/trunk/doc/reference/en/modules/configuration.xml
===================================================================
--- search/trunk/doc/reference/en/modules/configuration.xml 2008-09-04 16:05:47 UTC (rev
15154)
+++ search/trunk/doc/reference/en/modules/configuration.xml 2008-09-05 15:26:25 UTC (rev
15155)
@@ -636,7 +636,7 @@
performances, please refer to the Lucene documentation.</para>
<table>
- <title>List of indexing performance properties</title>
+ <title>List of indexing performance and behavior properties</title>
<tgroup cols="3">
<thead>
@@ -746,6 +746,21 @@
<entry>128</entry>
</row>
+
+ <row>
+
<entry><literal>hibernate.search.[default|<indexname>].indexwriter.[transaction|batch].use_compound_file</literal></entry>
+
+ <entry><para>Leaving this value to false is generally the best
+ performing option. You may need to enable it to have the index
+ written to a single compound file to use less file handlers, but
+ increasing the number of permitted file handlers is usually a
+ preferred solution.</para>
+ <para>Especially when synchronizing indexes using JMS avoid
+ this option as it will copy the complete index each time.</para>
+ <para>Boolean parameter, use
"<literal>true</literal>" or
"<literal>false</literal>".</para></entry>
+
+ <entry>false</entry>
+ </row>
</tbody>
</tgroup>
</table>
Modified:
search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java
===================================================================
---
search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java 2008-09-04
16:05:47 UTC (rev 15154)
+++
search/trunk/src/java/org/hibernate/search/backend/LuceneIndexingParameters.java 2008-09-05
15:26:25 UTC (rev 15155)
@@ -56,7 +56,7 @@
if ( log.isWarnEnabled() ) {
Integer maxFieldLengthTransaction = transParams.parameters.get( MAX_FIELD_LENGTH );
Integer maxFieldLengthBatch = transParams.parameters.get( MAX_FIELD_LENGTH );
- if ( notEquals( maxFieldLengthTransaction, maxFieldLengthBatch ) ){
+ if ( notEquals( maxFieldLengthTransaction, maxFieldLengthBatch ) ) {
log.warn( "The max_field_length value configured for transaction is different
than the value configured for batch." );
}
}
@@ -116,14 +116,14 @@
}
public Integer getCurrentValueFor(IndexWriterSetting ws){
- return parameters.get(ws);
+ return parameters.get( ws );
}
public void setCurrentValueFor(IndexWriterSetting ws, Integer newValue){
- if (newValue==null){
- parameters.remove(ws);
+ if ( newValue == null ) {
+ parameters.remove( ws );
} else {
- parameters.put(ws, newValue);
+ parameters.put( ws, newValue );
}
}
@@ -138,17 +138,17 @@
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if ( this == obj )
return true;
- if (obj == null)
+ if ( obj == null )
return false;
- if (getClass() != obj.getClass())
+ if ( getClass() != obj.getClass() )
return false;
final ParameterSet other = (ParameterSet) obj;
if (parameters == null) {
- if (other.parameters != null)
+ if ( other.parameters != null )
return false;
- } else if (!parameters.equals(other.parameters))
+ } else if ( ! parameters.equals( other.parameters ) )
return false;
return true;
}
Modified:
search/trunk/src/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java
===================================================================
---
search/trunk/src/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java 2008-09-04
16:05:47 UTC (rev 15154)
+++
search/trunk/src/java/org/hibernate/search/backend/configuration/ConfigurationParseHelper.java 2008-09-05
15:26:25 UTC (rev 15155)
@@ -67,4 +67,27 @@
return parseInt( propValue, defValue, "Unable to parse " + key + ":
" + propValue );
}
+ /**
+ * Parses a string to recognize exactly either "true" or "false".
+ * @param value the string to be parsed
+ * @param errorMsgOnParseFailure the message to be put in the exception if thrown
+ * @return true if value is "true", false if value is "false"
+ * @throws SearchException for invalid format or values.
+ */
+ public static final boolean parseBoolean(String value, String errorMsgOnParseFailure) {
+ // avoiding Boolean.valueOf() to have more checks: makes it easy to spot wrong type in
cfg.
+ if ( value == null ) {
+ throw new SearchException( errorMsgOnParseFailure );
+ }
+ else if ( "false".equalsIgnoreCase( value.trim() ) ) {
+ return false;
+ }
+ else if ( "true".equalsIgnoreCase( value.trim() ) ) {
+ return true;
+ }
+ else {
+ throw new SearchException( errorMsgOnParseFailure );
+ }
+ }
+
}
Modified:
search/trunk/src/java/org/hibernate/search/backend/configuration/IndexWriterSetting.java
===================================================================
---
search/trunk/src/java/org/hibernate/search/backend/configuration/IndexWriterSetting.java 2008-09-04
16:05:47 UTC (rev 15154)
+++
search/trunk/src/java/org/hibernate/search/backend/configuration/IndexWriterSetting.java 2008-09-05
15:26:25 UTC (rev 15155)
@@ -13,6 +13,7 @@
* @author Sanne Grinovero
*/
public enum IndexWriterSetting implements Serializable {
+
/**
* @see org.apache.lucene.index.IndexWriter#setMaxBufferedDeleteTerms(int)
*/
@@ -60,7 +61,7 @@
public void applySetting(IndexWriter writer, int value) {
writer.setRAMBufferSizeMB( value );
}
- },
+ } ,
/**
* @see org.apache.lucene.index.IndexWriter#setTermIndexInterval(int)
*/
@@ -68,8 +69,23 @@
public void applySetting(IndexWriter writer, int value) {
writer.setTermIndexInterval( value );
}
+ } ,
+ /**
+ * @see org.apache.lucene.index.IndexWriter#setUseCompoundFile(boolean)
+ */
+ USE_COMPOUND_FILE( "use_compound_file" ) {
+ public void applySetting(IndexWriter writer, int value) {
+ writer.setUseCompoundFile( intToBoolean( value ) );
+ }
+ @Override
+ public Integer parseVal(String value) {
+ return USE_COMPOUND_FILE.parseBoolean( value );
+ }
};
+ private static final Integer TRUE = Integer.valueOf( 1 );
+ private static final Integer FALSE = Integer.valueOf( 0 );
+
private final String cfgKey;
IndexWriterSetting(String configurationKey) {
@@ -99,4 +115,14 @@
"Invalid value for " + cfgKey + ": " + value );
}
+ private Integer parseBoolean(String value) {
+ boolean v = ConfigurationParseHelper.parseBoolean( value,
+ "Invalid value for " + cfgKey + ": " + value );
+ return v ? TRUE : FALSE;
+ }
+
+ private static boolean intToBoolean(int value) {
+ return value == TRUE.intValue();
+ }
+
}
Modified:
search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationParseHelperTest.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationParseHelperTest.java 2008-09-04
16:05:47 UTC (rev 15154)
+++
search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationParseHelperTest.java 2008-09-05
15:26:25 UTC (rev 15155)
@@ -13,7 +13,7 @@
*/
public class ConfigurationParseHelperTest extends TestCase {
- public void testIntegerParsers(){
+ public void testIntegerParsers() {
assertEquals( 0, ConfigurationParseHelper.parseInt( " 0 ", "not
important") );
assertEquals( 8, ConfigurationParseHelper.parseInt( null, 8, null ) );
assertEquals( 56, ConfigurationParseHelper.parseInt( "56", 8, null ) );
@@ -22,14 +22,34 @@
assertEquals( 58, ConfigurationParseHelper.getIntValue( props, "value1", 8 )
);
assertEquals( 8, ConfigurationParseHelper.getIntValue( props, "value2", 8 )
);
props.setProperty( "value2", "nand" );
- boolean exceptionLaunched;
+ boolean exceptionLaunched = false;
try {
ConfigurationParseHelper.getIntValue( props, "value2", 8 );
- exceptionLaunched = false;
} catch (SearchException e) {
exceptionLaunched = true;
}
assertTrue( exceptionLaunched );
}
+
+ public void testBooleanParsers() {
+ assertTrue( ConfigurationParseHelper.parseBoolean( "true", null ) );
+ assertTrue( ConfigurationParseHelper.parseBoolean( " True ", null ) );
+ assertFalse( ConfigurationParseHelper.parseBoolean( "false", null ) );
+ assertFalse( ConfigurationParseHelper.parseBoolean( " False ", null ) );
+ boolean exceptionLaunched = false;
+ try {
+ ConfigurationParseHelper.parseBoolean( "5", "error" );
+ } catch (SearchException e) {
+ exceptionLaunched = true;
+ }
+ assertTrue( exceptionLaunched );
+ exceptionLaunched = false;
+ try {
+ ConfigurationParseHelper.parseBoolean( null, "error" );
+ } catch (SearchException e) {
+ exceptionLaunched = true;
+ }
+ assertTrue( exceptionLaunched );
+ }
}
Modified:
search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
===================================================================
---
search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java 2008-09-04
16:05:47 UTC (rev 15154)
+++
search/trunk/src/test/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java 2008-09-05
15:26:25 UTC (rev 15155)
@@ -9,10 +9,12 @@
import org.hibernate.search.test.SerializationTestHelper;
import org.hibernate.search.test.query.Author;
import org.hibernate.search.test.query.Book;
+
import static
org.hibernate.search.backend.configuration.IndexWriterSetting.MAX_BUFFERED_DOCS;
import static
org.hibernate.search.backend.configuration.IndexWriterSetting.MAX_MERGE_DOCS;
import static
org.hibernate.search.backend.configuration.IndexWriterSetting.MERGE_FACTOR;
import static
org.hibernate.search.backend.configuration.IndexWriterSetting.RAM_BUFFER_SIZE;
+import static
org.hibernate.search.backend.configuration.IndexWriterSetting.USE_COMPOUND_FILE;
import static
org.hibernate.search.test.configuration.ConfigurationReadTestCase.TransactionType.TRANSACTION;
import static
org.hibernate.search.test.configuration.ConfigurationReadTestCase.TransactionType.BATCH;
@@ -25,6 +27,7 @@
super.configure( cfg );
cfg.setProperty( "hibernate.search.default.batch.ram_buffer_size",
"1" );
+ cfg.setProperty( "hibernate.search.default.batch.use_compound_file",
"true" );
//set by super : cfg.setProperty(
"hibernate.search.default.batch.max_buffered_docs", "1000" );
cfg.setProperty( "hibernate.search.default.transaction.ram_buffer_size",
"2" );
@@ -33,6 +36,7 @@
cfg.setProperty( "hibernate.search.default.transaction.max_buffered_docs",
"11" );
cfg.setProperty( "hibernate.search.Book.batch.max_merge_docs", "12"
);
+ cfg.setProperty( "hibernate.search.Book.transaction.use_compound_file",
"false" );
cfg.setProperty( "hibernate.search.Book.batch.merge_factor", "13"
);
// new keyword "indexwriter" is also supported to group parameters:
cfg.setProperty( "hibernate.search.Book.indexwriter.batch.max_buffered_docs",
"14" );
@@ -51,6 +55,8 @@
}
public void testDefaultIndexProviderParameters() throws Exception {
+ assertValueIsSet( Author.class, BATCH, USE_COMPOUND_FILE, 1 );
+ assertValueIsDefault( Author.class, TRANSACTION, USE_COMPOUND_FILE );
assertValueIsSet( Author.class, TRANSACTION, RAM_BUFFER_SIZE, 2 );
assertValueIsSet( Author.class, TRANSACTION, MAX_MERGE_DOCS, 9 );
assertValueIsSet( Author.class, TRANSACTION, MAX_BUFFERED_DOCS, 11 );
@@ -73,6 +79,7 @@
assertValueIsSet( Book.class, BATCH, MAX_MERGE_DOCS, 12 );
assertValueIsSet( Book.class, BATCH, MAX_BUFFERED_DOCS, 14 );
assertValueIsSet( Book.class, BATCH, MERGE_FACTOR, 13 );
+ assertValueIsSet( Book.class, TRANSACTION, USE_COMPOUND_FILE, 0 );
}
public void testInheritedBatchParametersFromTranscation() throws Exception {
@@ -95,8 +102,8 @@
LuceneIndexingParameters param = new LuceneIndexingParameters( new Properties() );
LuceneIndexingParameters paramCopy = (LuceneIndexingParameters)
SerializationTestHelper.duplicateBySerialization( param );
- assertEquals(param.getBatchIndexParameters(), paramCopy.getBatchIndexParameters());
- assertEquals(param.getTransactionIndexParameters(),
paramCopy.getTransactionIndexParameters());
+ assertEquals( param.getBatchIndexParameters(), paramCopy.getBatchIndexParameters() );
+ assertEquals( param.getTransactionIndexParameters(),
paramCopy.getTransactionIndexParameters() );
}
protected Class[] getMappings() {