Lucene.NET indexes are not updating when dealing with many-to-many relationships using NHibernate.Search

无人久伴 提交于 2020-01-01 19:38:10

问题


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

  • NHibernate.Search using Lucene.NET Full Text Index (Part 1)
  • Using NHibernate.Search with ActiveRecord

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.


回答1:


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'/>


来源:https://stackoverflow.com/questions/1328647/lucene-net-indexes-are-not-updating-when-dealing-with-many-to-many-relationships

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!