Searching through child objects nhibernate search?

448 views Asked by At

I have this kind of relationship

Supplier -> has many Products

Both Supplier is indexed and products are indexed. I need (boss wants to) search through both the Supplier and all of the suppliers' products and list the resulting suppliers.

Is this possible in nhibernate.search/Lucene.NET??

1

There are 1 answers

0
mathieu On BEST ANSWER

Yes it is possible : http://ayende.com/blog/3992/nhibernate-search

See the given example, IndexEmbedded attribute means the "child" object or collection will be indexed too :

[Indexed]
public class Post
{
    [DocumentId]
    public virtual int Id { get; set; }

    [IndexedEmbedded]
    public virtual Blog Blog { get; set; }

    [IndexedEmbedded]
    public virtual User User { get; set; }

    [Field(Index.Tokenized, Store = Store.Yes)]
    public virtual string Title { get; set; }

    [Field(Index.Tokenized)]
    public virtual string Text { get; set; }

    public virtual DateTime PostedAt { get; set; }

    public virtual ISet<Comment> Comments { get; set; }

    [IndexedEmbedded]
    public virtual ISet<Category> Categories { get; set; }

    [IndexedEmbedded]
    public virtual ISet<Tag> Tags { get; set; }
}