Hi guys,
I am attempting to use Hibernate search 3.2.1.Final with Lucene 3.0.2. For what it is worth, I am also using Spring utilising the @Configuration to wire my application.
A problem occurs (which I believe has been documented before) that the StandardAnalyzer cannot be instantiated because there is no default constructor as of Lucene 3.0.X.
Here is the relevent configuration:
Code:
AnnotationSessionFactoryBean sessionFactory =
new AnnotationSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setConfigurationClass(AnnotationConfiguration.class);
Properties hibernateProperties = new Properties();
// Hibernate configuration options
...
// Hibernate Search configuration options
hibernateProperties.setProperty("hibernate.search.default.directory_provider",
FSDirectoryProvider.class.getName());
hibernateProperties.setProperty("hibernate.search.default.indexBase",
indexDir.getAbsolutePath());
hibernateProperties.setProperty("hibernate.search.default.exclusive_index_use",
Boolean.TRUE.toString());
sessionFactory.setHibernateProperties(hibernateProperties);
sessionFactory.setAnnotatedClasses(ANNOTATED_CLASSES);
sessionFactory.afterPropertiesSet();
return sessionFactory.getObject();
And the relevant part of my stack trace is :
Code:
Caused by: org.hibernate.search.SearchException: org.apache.lucene.analysis.standard.StandardAnalyzer defined for component Lucene analyzer is missing a no-arguments constructor
at org.hibernate.search.util.PluginLoader.checkHasValidconstructor(PluginLoader.java:133)
at org.hibernate.search.util.PluginLoader.instanceFromClass(PluginLoader.java:79)
at org.hibernate.search.impl.InitContext.initAnalyzer(InitContext.java:112)
at org.hibernate.search.impl.InitContext.(InitContext.java:68)
at org.hibernate.search.impl.SearchFactoryImpl.initDocumentBuilders(SearchFactoryImpl.java:489)
at org.hibernate.search.impl.SearchFactoryImpl.(SearchFactoryImpl.java:171)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:126)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
So for now I have created my own class that extends StandardAnalyzer and I provide a no argument constructor like below. However I am not happy with this approach and it kinda feels like a hack.
Code:
public class ImagineAnalyzer extends StandardAnalyzer
{
public ImagineAnalyzer()
{
super(Version.LUCENE_30);
}
}
I was wondering if there was a fix planned in an upcoming release of hibernate search? If not, I have a suggested fix, which I would be happy to code and contribute if the authors thought it was the right approach. After looking at the class PluginLoader, it seems this is where a potential fix could be made. I am thinking that the method checkHasValidconstructor could return a Constructor object. Then in the instanceFromClass method call constructor.newInstance(). This would also require an additional hibernate search config option. Something like "hibernate.search.analyzer.version" which the user can optionally supply. This could default to the latest version. I realise that this is a pretty specific fix for the StandardAnalyzer, but this seems to be the most commonly used analyzer (based on my empirical observation), and if no analyzer is specified it is the default Analyzer that gets used.
Finally keep up the great work.
Cheers,
Ben