HibernateSearch ClassBridge - sorting and cutting that does not work with HS 5.5.1

I posted this some time ago in the sleep search forum and did not receive a response, so I will try again in stackoverflow ...

Since the transition from HS 4.5.1 to HS 5.5.1, we have problems with sorting and cutting.

All our indexing is done using a class bridge that calls the CDI Bean for actual indexing. In our system, the configuration whose fields are indexed is dynamic and may change at run time, so we cannot use HS annotations.

Sort: we would like to use the new lucene sort functions using docvalues. We tried to add the MetadataProvidingFieldBridge interface to the class bridge to provide information whose fields are sort fields, but while the class motif is initialized (when jboss is loaded), the CDI-Bean is not yet available.

Question 1: Is there a way to reinitialize the HS- SearchIntegrator at a later time, when the CDI-Bean is available or when our index configuration has changed? HS is currently reverting to using UninvertingReader to handle sort fields without docvalues.

Question 2 : Will it be supported in the future? How "bad" to use UninvertingReader performance?

We face a similar problem with faceting; we cannot use @Facet -nnotation because the configuration is dynamic. We are currently directly using the lucene faceting API.

Question 3 : Is there a plan in the HS to add face information across the class bridge in the near future, like MetadataProvidingFieldBridge ? Will the class bridge be supported by Hibernate Search in the future?

ClassBridge Code:

 public class FtiClassBridgeCE implements FieldBridge, MetadataProvidingFieldBridge { @Override public void set(String fieldName, Object value, Document document, LuceneOptions options) { if( !(value instanceof ComplexEntity)) return; // ignore ComplexEntity object = (ComplexEntity)value; // FtiService does the actual indexing by adding fields to given document Configuration.service( FtiService.class).setIndexData( object, new FtiDocumentHS( document, options)); } /* * This method is called in startup process of JBoss (Wildfly10) when initializing the persistence context. At that * time the CDI-Beans are not yet available resulting in a NullPointerException. * * @see org.hibernate.search.bridge.MetadataProvidingFieldBridge#configureFieldMetadata(java.lang.String, * org.hibernate.search.bridge.spi.FieldMetadataBuilder) */ public void configureFieldMetadata(String name, FieldMetadataBuilder builder) { try { // FtiService is a CDI bean which is obtained from BeanManager via our Configuration-class // FtiSearchConfig stores information which fields should be added to lucene index and how they map to // ComplexEntity data for( FtiSearchConfig config : Configuration.service( FtiService.class).getAllConfigurations()) { for( FtiSearchField ftiSearchField : config.getSortFields()) { builder.field( ftiSearchField.getNameForSort( null), hsSortType( ftiSearchField.getFieldDataType())).sortable( true); } } } catch( Exception ex) { ex.printStackTrace(); // catch the NPE thrown at JBoss boot time } } private FieldType hsSortType(FtiFieldDataType fieldDataType) { switch( fieldDataType) { case DATE: return FieldType.LONG; case NUMERIC: return FieldType.INTEGER; case PRICE: return FieldType.DOUBLE; default: return FieldType.STRING; } } 

In the @PostConstruct CDI Bean method, I tried to reinitialize the HS SearchIntegrator like this, but it did not call the FtiClassBridgeCE.configureFieldMetadata(String name, FieldMetadataBuilder builder) method again.

  @PostConstruct protected void initialize() throws ConfigurationException { initSearchConfig(); initializeHSSearch(); } private void initializeHSSearch() { FullTextEntityManager ftEM = ftidx().getFullTextEM(); SearchIntegrator si = ftEM.getSearchFactory().unwrap( SearchIntegrator.class); SearchIntegratorBuilder sb = new SearchIntegratorBuilder().currentSearchIntegrator( si); sb.buildSearchIntegrator(); } 

What is the correct way to do this or not being able to reinitialize the SearchIntegrator?

Stacktrace Exceptions that are loaded when JBoss loads during initialization of HS SearchIntegrator:

 13:33:12,656 INFO [jpa] (ServerService Thread) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'mc.ear/web.war#mc' 13:33:16,219 INFO [Dialect] (ServerService Thread) HHH000400: Using dialect: mc.core.system.util.db.SQLServerDialect 13:33:16,996 INFO [EnversServiceImpl] (ServerService Thread) Envers integration enabled? : true 13:33:23,864 INFO [UpdateTimestampsCache] (ServerService Thread) HHH000250: Starting update timestamps cache at region: mc.ear/web.war#mc.org.hibernate.cache.spi.UpdateTimestampsCache 13:33:25,675 INFO [StandardQueryCache] (ServerService Thread) HHH000248: Starting query cache at region: mc.ear/web.war#mc.org.hibernate.cache.internal.StandardQueryCache 13:33:27,529 INFO [Version] (ServerService Thread) HSEARCH000034: Hibernate Search 5.5.1.Final babysitten13:34:45,462 ERROR [stderr] (ServerService Thread) java.lang.NullPointerException 13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.weld.bean.builtin.BeanManagerProxy.<init>(BeanManagerProxy.java:74) 13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.as.weld.WeldProvider$CdiImpl.getBeanManager(WeldProvider.java:95) 13:34:45,463 ERROR [stderr] (ServerService Thread) at org.jboss.as.weld.WeldProvider$CdiImpl.getBeanManager(WeldProvider.java:73) 13:34:45,463 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.WorkerFactory.lookupBM(WorkerFactory.java:42) 13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.WorkerFactory.createService(WorkerFactory.java:28) 13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.configuration.Configuration.service(Configuration.java:27) 13:34:45,464 ERROR [stderr] (ServerService Thread) at mc.core.service.ftindex.hs.FtiClassBridgeCE.configureFieldMetadata(FtiClassBridgeCE.java:63) 13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getSortableFieldNames(AnnotationMetadataProvider.java:1751) 13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindClassBridgeAnnotation(AnnotationMetadataProvider.java:621) 13:34:45,464 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.bindClassBridgeAnnotation(AnnotationMetadataProvider.java:593) 13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClassLevelAnnotations(AnnotationMetadataProvider.java:546) 13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:430) 13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:130) 13:34:45,465 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:373) 13:34:45,466 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:199) 13:34:45,466 ERROR [stderr] (ServerService Thread) at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:117) 13:34:45,467 ERROR [stderr] (ServerService Thread) at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75) 13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35) 13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:530) 13:34:45,473 ERROR [stderr] (ServerService Thread) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.__build(SessionFactoryBuilderImpl.java:444) 13:34:45,474 ERROR [stderr] (ServerService Thread) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java) 13:34:45,474 ERROR [stderr] (ServerService Thread) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) 13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.__build(TwoPhaseBootstrapImpl.java:44) 13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java) 13:34:45,474 ERROR [stderr] (ServerService Thread) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) 
+5
source share

All Articles