hibernatesearch classbridge-sorting和faceting不适用于hs 5.5.1

6tr1vspr  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(257)

我前一段时间在hibernate搜索论坛上发布了这个,但没有得到任何回应,所以在stackoverflow中再次尝试。。。
由于从hs4.5.1迁移到hs5.5.1,我们在排序和刻面方面遇到了问题。
我们所有的索引都是通过调用cdibean的类桥来完成的。在我们的系统中,索引字段的配置是动态的,并且可以在运行时更改,因此我们不能使用hs注解。
排序:我们想利用lucene使用docvalues的新排序特性。我们试图添加接口 MetadataProvidingFieldBridge 向类桥提供哪些字段是排序字段的信息,但是在初始化类桥时(当jboss启动时),cdibean还不可用。
问题1:有没有办法重新初始化hs- SearchIntegrator 稍后,当cdibean可用时,或者当我们的索引配置改变时?目前,hs退回到使用 UninvertingReader 用于处理没有docvalue的排序字段。
问题二:这在未来会得到支持吗?使用性能有多差 UninvertingReader ?
对于刻面,我们面临着一个类似的问题,我们不能使用 @Facet -因为配置是动态的。目前我们直接使用lucene的faceting api。
问题3:hs中是否有计划在不久的将来通过类桥添加分面信息,类似于 MetadataProvidingFieldBridge ? 将来hibernate搜索会支持类桥吗?
类桥代码:

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 -我试图像这样重新初始化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启动时引发的异常的stacktrace:

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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题