Hibernate Search + Spring + JPA + 2个Webapp-正确的配置 [英] Hibernate Search + Spring + JPA + 2 webapps - correct configuration

查看:102
本文介绍了Hibernate Search + Spring + JPA + 2个Webapp-正确的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经过漫长而艰苦的搜索,无法找到明确的答案.

I have search long and hard, and cannot find a definitive answer.

我在tomcat的单个实例上运行了2个webapp:/server/ROOT

I have 2 webapps running on a single instance of tomcat: /server and /ROOT

我已经为我的一个实体(即Products)配置了Hibernate Search.

I have configured Hibernate Search configured for one of my entities, ie Products.

这些实体在/server上进行了编辑/添加,并由前端用户在/ROOT

These entities are edited/added on /server and searched for by front end users on the website /ROOT

在正常操作期间,一切正常进行,在服务器上编辑实体将导致那些更改,反映在前端进行搜索时.

during normal operations, everything works as it should, editing entities on the server will result in those changes reflecting when doing a search on the front end.

但是,在不确定的时间或事件序列之后,索引不再得到更新.

however, after an undetermined time, or sequence of events, the index no longer gets updated.

这是/server

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="jpaDataSource" />
    <property name="packagesToScan" value="com.foo" />
    <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="generateDdl" value="true" />
                    <property name="showSql" value="true" />
            </bean>
    </property>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}" />
</util:map>

这是/ROOT

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.foo" />
    <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="generateDdl" value="true" />
                    <property name="showSql" value="true" />
            </bean>
    </property>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}" />
</util:map>

基本上相同.

这是通过AspectJ ITD配置我的实体的方式

and here is how my Entity is configured, via an AspectJ ITD

privileged aspect Product_Search {

declare @type: Product: @Indexed;

declare @method :public Long Product.getId() : @DocumentId;
declare @method :public String Product.getTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSubTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getAlternativeTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getIdentifier() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getPrimaryCreators() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSecondaryCreators() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSubjectArea() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getPublisher() : @Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO);
declare @method :public String Product.getTags() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);

进一步搜索后,我发现了主/从DirectoryProvider

Upon further searching, I discovered the master/slave DirectoryProvider

/server

    <util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem-master" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}/primary" />
    <entry key="hibernate.search.default.sourceBase" value="${lucene.index.folder}/master" />
    <entry key="hibernate.search.default.refresh" value="120" />
</util:map>

/ROOT

    <util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem-slave" />
    <entry key="hibernate.search.default.sourceBase" value="${lucene.index.folder}/master" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}/slave" />
    <entry key="hibernate.search.default.refresh" value="300" />
</util:map>

这似乎一直有效,直到今天早些时候,由于某种原因,我的索引本身重置"了,并且只包含了上次产品导入中的项目. 我的意思是,我的数据库有10000个项目,但是如果我执行query = new MatchAllDocsQuery();,我只会得到15个(最后一次导入的大小)

This seemed to work, until earlier to day, when for some reason, my index "reset" itself, and only contained the items that were part of the last product import. What I mean is, that my DB has 10000 items, but if I did a query = new MatchAllDocsQuery();, I only got 15 (the size of the last import)

这真的使我发疯.

此刻,我必须关闭网站,删除索引,启动服务器,然后使用FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager()); fullTextEntityManager.createIndexer().startAndWait();

At the moment, I am having to bring down the websites, delete the index, start the server, reindex using FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager()); fullTextEntityManager.createIndexer().startAndWait();

让我知道是否需要更多信息

Let me know if you need any more info

谢谢

推荐答案

如果仅通过 server 应用程序进行更改,而您始终想运行 server 和<在同一台计算机上的em> ROOT ,无需进行主/从设置.应该执行一个简单的文件系统设置,但是,您要确保在 ROOT 应用程序上指定了_hibernate.search.indexing_strategy = manual_.只有在 ROOT 应用程序上使用了显式索引API时,索引更新才会发生.

If changes are only coming in via the server app and you always want to run server and ROOT on the same machine, there is no need for a master/slave setup. A simple filesystem setup should do, however, you want to make sure that on the ROOT app _hibernate.search.indexing_strategy = manual_ is specified. This way index updates would only occur when the explicit indexing API is used on the ROOT app.

您打开日志记录了吗?日志中是否有任何内容.我认为第一步是尝试以可靠的方式重现该问题.如果您只是说它最初起作用,但随后突然开始失败,则很难找到原因.您是否尝试过一些自动负载测试?

have you turned on logging? Is there anything in the logs. I think the first step is trying to reproduce the problem in a reliable way. If you just say it works initially, but then suddenly it starts failing, it makes it hard to find the cause. Have you tried with some automated load tests?

这篇关于Hibernate Search + Spring + JPA + 2个Webapp-正确的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆