日期:2014-05-16  浏览次数:20551 次

Compass集成Hibernate实现索引与数据库同步
Compass通过监听Hibernate对实体的增、删、改来实现对索引的增、删、改
<bean id="compass" class="org.compass.spring.LocalCompassBean">
<!-- 实体所在的包名 -->
<property name="mappingScan" value="cn.shop.model" />
<!-- 在内存中建立索引<prop key="compass.engine.connection">ram://index</prop>-->
<property name="connection">
<value>/lucene</value>
</property>
<property name="compassSettings">
<props>
<!-- 设置分词器 -->
<prop key="compass.engine.analyzer.default.type">net.paoding.analysis.analyzer.PaodingAnalyzer</prop>
<prop key="compass.engine.highlighter.default.formatter.simple.pre"><![CDATA[<font color='red'>]]></prop>
<prop key="compass.engine.highlighter.default.formatter.simple.post"><![CDATA[</font>]]></prop>
<prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory
</prop>
</props>
</property>
<property name="transactionManager" ref="txManager" />
</bean>

<!-- 自动完成 索引的添加/更新/删除操作-->
<bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps"
init-method="start" destroy-method="stop">
<property name="compass" ref="compass" />
<property name="gpsDevices">
<list>
<!-- 设置Hibernate驱动 -->
<bean
class="org.compass.spring.device.hibernate.dep.SpringHibernate3GpsDevice">
<property name="name" value="hibernateDevice" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</list>
</property>
</bean>