使用 NHibernate.Search 处理多对多关系时,Lucene.NET 索引不会更新

发布于 2024-08-02 09:10:07 字数 1369 浏览 4 评论 0原文

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

我还成功地对我的数据库进行了批量索引,并且在针对 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")) 之类的操作时,我可以看到我的作者索引已更新,但是图书索引(这是父索引)尚未更新,搜索新添加的作者将返回空结果。

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

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

I have integrated NHibernate.Search into my web app by following tutorials from the following sources:

I have also successfully batch-indexed my database, and when testing against Luke, I can search for terms that reside in whatever entities I marked as indexable.

However, when I attempt to update many-to-many entities via my web app, my parent index does not seem to update. For example:

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; }
     }
}

Now, when I try to do things like myBook.Authors.Add(Author.Create("xxx")) I can see that my Author index has been updated, however, the Book index (which is the parent index) has not been updated and searching for the newly added author returns an empty result.

Note that this only happens when dealing with many-to-many relationships.

I am not sure why this is so. Has anyone else experienced similar difficulties? I'd appreciate it if I could be pointed in the right direction, cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长发绾君心 2024-08-09 09:10:07

我最近更新了 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'/>

I've recently updated the trunk of NHibernate Search to fix this issue. You will have to download and compile the latest code and modify your config with the appropriate listeners for the collection changes to propogate...

<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'/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文