我想做个Spring 和 Hibernate - Search 整和的搜索模块
可是失败了,整合没问题,没有错误...
但是Hibernate进行保存的时候,能保存进数据库,但是索引没有建立!
配置如下:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3309/cs4m</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="connection.autocommit">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
<property name="hibernate.search.default.indexBase">D:/temp/index</property>
<property name="hibernate.search.autoregister_listeners">true</property>
<property name="hibernate.search.indexing_strategy">manual</property>
<mapping class="com.cs4m.vo.VOTest"/>
</session-factory>
</hibernate-configuration>
------------------------ Spring -----------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="com.cs4m"/>
<aop:aspectj-autoproxy/>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > -->
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hbmtpl" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
我使用的是Annotation的配置方式
实体如下:
@Entity
@Table(name="ttttt")
@Indexed(index="ttttt")
public class VOTest {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@DocumentId
private int id;
@Column(name="asdf")
@Field(index=Index.UN_TOKENIZED,store=Store.YES,boost=@Boost(value=2.0f))
private String name;
@Column(name="asdfdd",length=5000)
@Field(analyzer=@Analyzer(impl=PaodingAnalyzer.class),index=Index.TOKENIZED,store=Store.YES)
private String text;
...get、set省略...
测试如下:
--------JUnit4测试--------
public class TestHibernate {
public AbstractApplicationContext ac = null;
public HibernateTemplate t = null;
@Test
public void test1(){
ac = new ClassPathXmlApplicationContext("applicationContext.xml");
t = (HibernateTemplate)ac.getBean("hbmtpl");
Session s = t.getSessionFactory().openSession();
FullTextSession fs = Search.getFullTextSession(s);
for(int i = 0;i<10;i++){
VOTest vt = new VOTest();
vt.setName("xxxxxxxx");
vt.setText("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
fs.save(vt);
}
fs.flush();
}
}
运行过程没有错误,数据库上有数据,但是索引目录没有看到有索引文件,搜索也没有结果
我在没有用Spring 整合之前用过Hibernate-Search,很成功,一点问题没有
各位高手给解答一下吧!
谢谢