FullTextQuery with field projections doesn't populate fields from IndexEmbedded components or classes
Description
Environment
None
Attachments
1
- 18 Nov 2011, 02:36 PM
Activity
Show:

Josh Thompson November 18, 2011 at 2:36 PM
A patch for this issue
Who's Looking?
This is actually a very nice feature of NHibernate.Search, because it allows you to query against an lucene index without touching the database if one needs only stored fields from an entity.
Consider the following model:
[Indexed] public class Document { [DocumentId] public virtual Guid Id { get; set; } [Field(Index.Tokenized, Store = NHibernate.Search.Attributes.Store.Yes)] public virtual string Title { get; set; } [Field(Index.Tokenized, Store = NHibernate.Search.Attributes.Store.No)] public virtual string Body { get; set; } [IndexedEmbedded(Prefix = "User.")] public virtual UserDetails User { get; set; } } public class UserDetails { [Field(Store = NHibernate.Search.Attributes.Store.Yes)] public virtual string Username { get; set; } [Field(Store = NHibernate.Search.Attributes.Store.Yes)] public virtual string FullName { get; set; } }
I would like to perform a fulltext query and I need only Id, Title, User.FullName fields from this document
var results = session.CreateFullTextQuery<Document>("Title:django") .SetProjection("Id", "Title", "User.FullName") .SetMaxResults(5) .List();
The problem is a result item does not containt the "User.FullName" field. It seems that the problem is in the DocumentBuilder.ProcessFieldsForProjection private method. This method calls itself for each embedded mapping, but never uses the "Prefix" property of the embeddedmapping class. ITwoWayFieldBridge.Get("User.FullName", document) is ok, however