【问题标题】:Lucene.NET indexes are not updating when dealing with many-to-many relationships using NHibernate.Search使用 NHibernate.Search 处理多对多关系时,Lucene.NET 索引不会更新
【发布时间】:2009-08-25 14:27:05
【问题描述】:

我已按照以下来源的教程将 NHibernate.Search 集成到我的网络应用程序中:

我还成功地对我的数据库进行了批量索引,并且在针对 Luke 进行测试时,我可以搜索驻留在我标记为可索引的任何实体中的术语。

但是,当我尝试通过我的网络应用更新多对多实体时,我的父索引似乎没有更新。例如:

public class Books
{
    HasAndBelongsToMany(typeof(Author), Table = "BookAuthor", ColumnKey = "BookId", ColumnRef = "AuthorId")]
    [IndexedEmbedded]
    public IList<Author> Authors
    {
        get { return authors; }
        set { authors = value; }
     }
}

public class Author
{
    HasAndBelongsToMany(typeof(Book), Table = "BookAuthor", ColumnKey = "AuthorId", ColumnRef = "BookId"), Inverse=true]
    [ContainedIn]
    public IList<Author> Authors
    {
        get { return authors; }
        set { authors = value; }
     }
}

现在,当我尝试执行myBook.Authors.Add(Author.Create("xxx")) 之类的操作时,我可以看到我的作者索引已更新,但是图书索引(即父索引)尚未更新,搜索新添加的作者返回一个空的结果。

请注意,这只发生在处理多对多关系时。

我不知道为什么会这样。有没有其他人遇到过类似的困难?如果我能指出正确的方向,我将不胜感激,干杯。

【问题讨论】:

  • 事实证明,NHibernate.Search 可能没有完全实现索引多对多关系。如果我错了,请有人纠正我。

标签: .net lucene.net castle-activerecord nhibernate.search


【解决方案1】:

我最近更新了 NHibernate Search 的主干来解决这个问题。您必须下载并编译最新代码,并使用适当的侦听器修改您的配置,以便传播集合更改...

<listener class='NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search' type='post-insert'/>
<listener class='NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search' type='post-update'/>
<listener class='NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search' type='post-delete'/>
<listener class='NHibernate.Search.Event.FullTextIndexCollectionEventListener, NHibernate.Search' type='post-collection-recreate'/>
<listener class='NHibernate.Search.Event.FullTextIndexCollectionEventListener, NHibernate.Search' type='post-collection-remove'/>
<listener class='NHibernate.Search.Event.FullTextIndexCollectionEventListener, NHibernate.Search' type='post-collection-update'/>

【讨论】:

  • 当我使用cfg.SetListener(ListenerType.PostCollectionRecreate, new FullTextIndexCollectionEventListener()); 时,它会抛出Attempted to access an element as a type incompatible with the array. 异常。有什么建议吗?
  • FullTextIndexCollectionEventListener 为空就好了? nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/branches/…
  • 没关系...仅在分支版本中。有什么消息会在 nh3.x nh.s 分支中加入吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多