我刚刚在hibernate搜索论坛上发布了这个并没有得到任何响应,所以再次尝试在stackoverflow中...
自从HS 4.5.1迁移到HS 5.5.1后,我们在排序和分面方面遇到了问题。
我们所有的索引都是使用类桥来完成的,该类调用CDI-Bean来进行实际索引。在我们的系统中,索引哪些字段的配置是动态的,并且可以在运行时更改,因此我们不能使用HS注释。
排序:我们希望利用docceues利用lucene的新排序功能。我们尝试将接口MetadataProvidingFieldBridge
添加到类桥接器以提供哪些字段是排序字段的信息,但是当类桥接器被初始化时(当jboss启动时)CDI-bean还不可用。 / p>
问题1:当CDI-bean可用或我们的索引配置发生变化时,有没有办法在以后重新初始化HS - SearchIntegrator
?
目前HS回归到使用UninvertingReader
来处理没有docvalues的排序字段。
问题2 :将来会支持这个吗?使用UninvertingReader
在性能上有多“糟糕”?
使用分面我们面临类似的问题,我们不能使用@Facet
- 注释,因为配置是动态的。目前我们直接使用lucene的faceting API。
问题3 :HS中是否有计划在不久的将来通过类桥添加分面信息,类似于MetadataProvidingFieldBridge
?这个类桥将来会被Hibernate Search支持吗?
ClassBridge的代码:
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's 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;
}
}
在@PostConstruct
- CDI-Bean的方法中,我尝试重新初始化HS SearchIntegrator,但它没有再次调用方法FtiClassBridgeCE.configureFieldMetadata(String name, FieldMetadataBuilder builder)
。
@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();
}
这是执行此操作的正确方法,还是无法重新初始化SearchIntegrator?
初始化HS SearchIntegrator时在JBoss启动时抛出的异常的堆栈跟踪:
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)