views:

286

answers:

1

How do I query for data added as IndexEmbedded?
I have an entity class

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

    [IndexedEmbedded]
    public virtual Category Category { get; set; }
    [IndexedEmbedded]
    public virtual Location Location { get; set; }
  }

Location as

[Indexed]
  public class Location 
  {
    /// </summary>            
    [Field(Index.Tokenized, Store = Store.Yes)]
    public virtual string Address
    {
  }

Data gets added(both for normal properties and IndexEmbedded) to the index and I can see them using Luke.
However when I query using Fulltext I get valid results only for the normal properties and not for IndexedEmbedded
e.g. "sample description" => 1 result, " Palo Alto" => 0 results(both of them are in the index) This is my query

using (IFullTextSession s = Search.CreateFullTextSession(NHibernateSession.GetSession())) {
        MultiFieldQuerParser qp = new MultiFieldQueryParser(new[] {
                                                                     “Description”,“Title”,”Name”
                                                                   }, new StandardAnalyzer());
        IQuery NHQuery = s.CreateFullTextQuery(qp.Parse(query), typeof(Something));
        result = NHQuery.List();

Am I doing something wrong or missing anything?

+2  A: 

From what i see, you're not referencing the fields for the IndexedEmbedded collections. You should add the following fields in your MultiFieldQueryParser

new MultiFieldQueryParser(new[] {"Description", "Title", "Name", "Location.Address"})

The correct names for the fields should be visible in Luke, prefixed with the property name you applied the IndexedEmbedded attribute to.


edit: If the default prefixing is not to your liking, you can change it with the prefix argument of the IndexedEmbedded attribute

samy