[
https://hibernate.onjira.com/browse/HSEARCH-1088?page=com.atlassian.jira....
]
Hardy Ferentschik updated HSEARCH-1088:
---------------------------------------
Description:
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}
was:
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:
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()
...
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)
hibernate-search-4.1.0.CR3/project/hibernate-search-engine/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java.diff:
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" ) ) {
Pull Requests:
https://github.com/hibernate/hibernate-search/pull/277 (was:
https://github.com/hibernate/hibernate-search/pull/277)
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