Question

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.

Was it helpful?

Solution

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'/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top