I am messing around with NHibernate Search and Lucene to create a searchable index of legal entities. My domain model looks somewhat like this:
[Indexed]
public abstract class LegalEntity : AggregateRoot
{
public virtual Address Address { get; set; }
}
public class Person : LegalEntity
{
public virtual string FirstNames { get; set; }
public virtual string LastName { get; set; }
}
public class Company: LegalEntity
{
public virtual string Name { get; set; }
}
public class Address : Component
{
public virtual string Street { get; set; }
public virtual string HouseNumber { get; set; }
// etc...
}
As the subclassing implies, LegalEntity
is an NHibernate entity specialized as Person
and Company
, and Address
is an NHibernate component.
Now, how would I best go about creating a really Google-like fuzzy search that includes all the fields of a LegalEntity
, including those inside the Address
component?
My first idea was to implement an AddressFieldBridge
to help in bringing in the fields of the Address
component, and then just throw in [Field]
on all the fields, but then I could not find a way to construct a FuzzyQuery
as a conjuntion between multiple search terms.
My next idea was to create an abstract property tagged with [Field]
on LegalEntity
, like so:
[Field(Index.Tokenized)]
public abstract string SearchableText { get; }
and then have Person
and Company
return texts that combine names and all the fields from the Address
component into one string, which would then be tokenized and indexed by Lucene.
That, however, made me feel kind of icky.
I would like to learn the best and least intrusive (from a domain model perspective) way to accomplish this task - any suggestions are appreciated :)