views:

248

answers:

1

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.

+1  A: 

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'/>
Paul Hatcher
When i use `cfg.SetListener(ListenerType.PostCollectionRecreate, new FullTextIndexCollectionEventListener());`, it throws `Attempted to access an element as a type incompatible with the array.` exception. Any tips on that?
Arnis L.
It's fine that FullTextIndexCollectionEventListener is empty? https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/branches/NHibernate.Search-NH3.x/NHibernate.Search/Event/FullTextIndexCollectionEventListener.cs
Arnis L.
Nevermind... that's in branch version only. Any news when it will be included in nh3.x nh.s branch?
Arnis L.