[hibernate-issues] [Hibernate-JIRA] Resolved: (HSEARCH-1088) Specifying an analyzer on an entity class bridge using the programmatic API is broken

Hardy Ferentschik (JIRA) noreply at atlassian.com
Tue Apr 24 11:29:49 EDT 2012


     [ https://hibernate.onjira.com/browse/HSEARCH-1088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hardy Ferentschik resolved HSEARCH-1088.
----------------------------------------

    Resolution: Fixed

> Specifying an analyzer on an entity class bridge using the programmatic API is broken
> -------------------------------------------------------------------------------------
>
>                 Key: HSEARCH-1088
>                 URL: https://hibernate.onjira.com/browse/HSEARCH-1088
>             Project: Hibernate Search
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 4.1.0.CR3, 4.1.0.Final
>         Environment: Hibernate 4.1.1.Final
>            Reporter: Michael Heinrichs
>            Assignee: Sanne Grinovero
>              Labels: candidate_for_next
>             Fix For: 4.2
>
>         Attachments: MappingModelMetadataProvider.java.diff
>
>
> The programmatic API provides the ability to specify an analyzer on an entity class bridge (ClassBridgeMapping), but during initialization, an exception is thrown.  See below for an example search mapping, exception stack trace, and the diff for my fix.
> I modified the Hibernate Search code by copying the analyzer initialization code from the creation of fields into the creation of class bridges.  It appears that there may be other attributes that are not being properly processed for class bridges, but this fix solves my immediate problem.
> Here is an example:
> {code}
>         SearchMapping searchMapping = new SearchMapping();
>         searchMapping
>         	.analyzerDef("customanalyzer", StandardTokenizerFactory.class)
>         		.filter(LowerCaseFilterFactory.class)
>         		.filter(NGramFilterFactory.class)
>         			.param("minGramSize", "3")
>         			.param("maxGramSize", "3")
>         	.entity(Person.class)
>         		.classBridge(NameAppendingBridge.class)
>         			.name("fullName")
>         			.analyzer("customanalyzer")
>         			.index(Index.YES)
>         			.store(Store.YES)
>         			.param("fields", "frstName,othrName,lastName,mdnName")
>         		.indexed()
> ...
> {code}
> {noformat}
> java.lang.ClassCastException: java.util.HashMap cannot be cast to org.hibernate.search.annotations.Analyzer
> 	at $Proxy26.analyzer(Unknown Source)
> 	at org.hibernate.search.engine.spi.AbstractDocumentBuilder.bindClassBridgeAnnotation(AbstractDocumentBuilder.java:885)
> 	at org.hibernate.search.engine.spi.AbstractDocumentBuilder.initializeClassLevelAnnotations(AbstractDocumentBuilder.java:425)
> 	at org.hibernate.search.engine.spi.AbstractDocumentBuilder.initializeClass(AbstractDocumentBuilder.java:352)
> 	at org.hibernate.search.engine.spi.AbstractDocumentBuilder.<init>(AbstractDocumentBuilder.java:151)
> 	at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.<init>(DocumentBuilderIndexedEntity.java:179)
> 	at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:419)
> 	at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:221)
> 	at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:145)
> 	at org.hibernate.search.event.impl.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:129)
> 	at org.hibernate.search.hcore.impl.HibernateSearchIntegrator.integrate(HibernateSearchIntegrator.java:82)
> 	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:304)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778)
> {noformat}
> hibernate-search-4.1.0.CR3/project/hibernate-search-engine/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java.diff:
> {noformat}
> 575c575,584
> <                               if ( entry.getKey().equals( "params" ) ) {
> ---
> >                               if ( entry.getKey().equals( "analyzer" ) ) {
> >                                       AnnotationDescriptor analyzerAnnotation = new AnnotationDescriptor( Analyzer.class );
> >                                       @SuppressWarnings("unchecked")
> >                                       Map<String, Object> analyzer = (Map<String, Object>) entry.getValue();
> >                                       for ( Map.Entry<String, Object> analyzerEntry : analyzer.entrySet() ) {
> >                                               analyzerAnnotation.setValue( analyzerEntry.getKey(), analyzerEntry.getValue() );
> >                                       }
> >                                       annotation.setValue( "analyzer", AnnotationFactory.create( analyzerAnnotation ) );
> >                               }
> >                               else if ( entry.getKey().equals( "params" ) ) {
> {noformat}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list