论坛首页 入门技术论坛

请教:spring+hbernate search+spring mvc建立索引问题

浏览 2701 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-04-25  

最近做了个hibernate search搜索,但出现了一个问题,就是save()时不能建立索引(保存时有'刘宗安'这个数据的), 我用下面的代码:

  Query query = parser.parse("刘宗安");
   org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, clz);
   result = hibQuery.list();

 查询不出来啊,result返回0,但保存时在我的索引目录下自动新件了一个文件(好像是索引文件,但是查询不出来),现在用代码手动方式建立索引

List<SubPhoto> subPhotoL = super.getObjects();
      for (SubPhoto subPhotoIndex : subPhotoL)
     {
            fullTextSession.index(subPhotoIndex);
      }

 再进行查询,result就有数据了,但我发现我删除一条记录时,可以删除索引(我测试过了)

我的jar是:hibernate-annotations-3.3.1.GA    hibernate-search-3.0.1.GA  hibernate-3.2.6.ga

spring2.5

我不知道是否要加这个Listener(我没有加)

<hibernate-configuration>
<session-factory>
...
<event type="post-collection-recreate"/>
<listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>
<event type="post-collection-remove"/>
<listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>
<event type="post-collection-update"/>
<listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>
</session-factory>
</hibernate-configuration>

 好像下面一句话说,不用加了listener

Those additional event listeners have been introduced in Hibernate 3.2.6. note the FullTextIndexCollectionEventListener
usage. You need to explicitly reference those event listeners unless you use Hibernate Annotations
3.3.1 and above.

是不是这样啊?????

   发表时间:2008-04-25  
已经解决!!!
0 请登录后投票
   发表时间:2008-06-14  
请问你是怎么解决的?我也出现类似的问题,
还有,我的那个listener和你的不一样,

<event type="post-commit-update">
	<listener	class="org.hibernate.lucene.event.LuceneEventListener" />
</event>
<event type="post-commit-insert">
	<listener
	class="org.hibernate.lucene.event.LuceneEventListener" />
</event>
<event type="post-commit-delete">
	<listener
	class="org.hibernate.lucene.event.LuceneEventListener" />
</event>


谢谢了!QQ:358665570
0 请登录后投票
   发表时间:2008-06-24  
就是生成实体类的问题,没有标识主键的生成方式
0 请登录后投票
   发表时间:2008-07-23  
直接按照hibernate annottion文档标识UUID生存即可,不需要改动其它地方
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics