-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: instantiating StandardAnalyzer using Lucene 3.x
PostPosted: Thu Sep 02, 2010 6:11 am 
Newbie

Joined: Wed Jan 28, 2009 9:46 am
Posts: 10
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

_________________
http://www.fotegrafik.com


Top
 Profile  
 
 Post subject: Re: instantiating StandardAnalyzer using Lucene 3.x
PostPosted: Thu Sep 02, 2010 8:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

you are right, the latest Search version is not compatible with Lucene 3.x. We are working on upgrading - see HSEARCH-424. There are actually more issues than just the change in analyzer constructors. Thanks for your ideas though. For custom analyzers we indeed intend will do something along the lines you are suggesting. It works for your own custom analyzers. Unfortunately, we also have a problem with the Solr analyzer configuration framework which we expose via the @AnalyzerDef annotation. Solr hasn't released a 3.x compatible version of its framework yet. We are working on a workaround though.

thanks for your feedback,
Hardy


Top
 Profile  
 
 Post subject: Re: instantiating StandardAnalyzer using Lucene 3.x
PostPosted: Thu Sep 02, 2010 10:04 am 
Newbie

Joined: Wed Jan 28, 2009 9:46 am
Posts: 10
Hi Hardy,

Thanks for the info and taking the time to answer. I took a look at Jira issue you linked. You weren't kidding when you said there are more issues than just the analyzer constructors :) I guess it will be a little bit longer before HS is compatible with Lucene 3.0.x

thanks again,
Ben

_________________
http://www.fotegrafik.com


Top
 Profile  
 
 Post subject: Re: instantiating StandardAnalyzer using Lucene 3.x
PostPosted: Fri Sep 03, 2010 3:00 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Most of the sub-tasks of HSEARCH-424 are optional improvements, so it might not take very long; I hope next beta will have Lucene 3, but likely not using all new cool things.

The real pain is that the Lucene team itself didn't release a compatible Solr, so even the latest version of Solr is using Lucene 2.9; luckily almost all benefits of Lucene 3 are backported to 2.9. The issue with solr is the same as your analyzers, they didn't upgrade to the new constructor strategy.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: instantiating StandardAnalyzer using Lucene 3.x
PostPosted: Fri Sep 03, 2010 4:02 am 
Newbie

Joined: Wed Jan 28, 2009 9:46 am
Posts: 10
Hi Sanne,

Quote:
Most of the sub-tasks of HSEARCH-424 are optional improvements, so it might not take very long; I hope next beta will have Lucene 3, but likely not using all new cool things.

That's really nice to hear. I will try the beta once it is released. Some of the new cool things are better than none though.

Quote:
The real pain is that the Lucene team itself didn't release a compatible Solr, so even the latest version of Solr is using Lucene 2.9;

I remember reading something along those lines. Interesting they did that. I guess time/resources are limited.

Quote:
luckily almost all benefits of Lucene 3 are backported to 2.9

This I did not know. Thanks for the heads up and providing me more details, I really appreciate it.

Cheers,
Ben

_________________
http://www.fotegrafik.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.