简体   繁体   English

在JBoss 7.1.1 Final,Weld和Seam 3上进行Hibernate搜索

[英]Hibernate Search on JBoss 7.1.1 Final, Weld and Seam 3

I'm running an application that uses hibernate search for looking up people in the system. 我正在运行一个使用休眠搜索在系统中查找人员的应用程序。 I run it on JBoss AS 7.1.1 and the application is based on Seam 3, Weld and JSF 2.1. 我在JBoss AS 7.1.1上运行它,该应用程序基于Seam 3,Weld和JSF 2.1。 It's working smoothly but after some higher load it turns out that pages that use the FullTextEntityManager are being loaded very slowly. 它工作正常,但是在较高的负载之后,发现使用FullTextEntityManager页面的加载速度非常慢。 And in some moments the whole application is slowing down. 有时,整个应用程序会变慢。

So it got to my mind that maybe I'm using Hibernate search incorrectly. 因此,我想到也许我没有正确使用Hibernate搜索。 I'm using a startup singleton to index the database: 我正在使用启动单例来索引数据库:

@Singleton
@Startup
public class Initializer implements Serializable {

    private static final long serialVersionUID = 1L;

    @PersistenceContext
    private EntityManager entityManager;

    @PostConstruct
    public void startup() throws Exception {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        fullTextEntityManager.createIndexer().startAndWait();
    }

}

And then I use the FullTextEntityManager in the method that is used in an autocomplete component of PrimeFaces: 然后,我在PrimeFaces的自动完成组件中使用的方法中使用FullTextEntityManager

@Session Scoped
public class ... {

        private QueryBuilder queryBuilder;

        @Inject
        private EntityManager entityManager;

        @PostConstruct
        public void initFulltext() {
            fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
            queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get();

        }

        @Override
        @SuppressWarnings("unchecked")
        public List<Person> autocomplete(Object event) throws Exception {
            if (event.toString() != null && !event.toString().trim().isEmpty()) {
                org.apache.lucene.search.Query query = queryBuilder.keyword()
                        .onFields("username", "firstname", "lastname").matching(event.toString())
                        .createQuery();

                FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Person.class);
                persistenceQuery.setMaxResults(MAX_RESULTS_ON_PAGE);

                return persistenceQuery.getResultList();
            }
            return null;
        }
}

Is this a correct usage of Hibernate Search in a Java EE application? 这是Java EE应用程序中Hibernate Search的正确用法吗? Isn't it possible that after a while hibernate search is trying to synchronize changes of entities and the Lucene index? 经过一段时间的休眠搜索后,是否有可能试图同步实体和Lucene索引的更改? If so, is it possible that it causes a huge impact on performance? 如果是这样,是否有可能对性能造成巨大影响?

It is correct usage of hibernate search i would say. 我会说这是休眠搜索的正确用法。 Its the field cache that is degrading performance for you. 它的字段缓存会降低您的性能。 This is actualy query dependent. 这实际上取决于查询。 Reacd through section 5.5 here ,should be of some help. 通过此处的 5.5节,应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM