views:

139

answers:

2

Using Nhibernate.Search at the moment.

Some code for context:

[Indexed]
class foo {
  [DocumentId]
  int id {get;set;}
  bar bar {get;set;}
}

[Indexed]
class bar {
  [DocumentId]
  int id {get;set;}
}

Question:
How to retrieve all foos where foo.bar.id==1 using IFullTextQuery?

A: 

Seems that [IndexedAttribute] is an answer.

Arnis L.
Actually - i mean here IndexedEmbedded. That was typo.
Arnis L.
+1  A: 

If you want to include related information into the foo index you may look into the IndexedEmbeddedAttribute. This will allow you to query for relationships such as if there was a Name property on the bar object you could create a query such as this

IFullTextQuery query = search.CreateFullTextQuery("bar.Name:Arnis");
query.List<foo>();
Andrew Smith
you have to be careful when using the IndexedEmbeddedAttribute because it requires more entities to have to be loaded at indexing time.
Andrew Smith
What if i need to add this clause to query that's made with MultiFieldQueryParser?
Arnis L.
In the constructor of the MutliFieldQueryParser it allows you to pass in a string array of fields that you want to search. Just pass in the "bar.Name" field as one of your fields.
Andrew Smith