我正在索引 2 个不同的文档,如下所示。
public class User
{
public UserId UserId { get; set; }
public string DisplayName { get; set; }
}
public class UserGroup
{
public UserGroupId UserGroupId { get; set; }
public string Name { get; set; }
}
//this is for indexing result
public class SecurityObject
{
public virtual Guid Id { get; set; }
public virtual string DisplayName { get; set; }
public virtual SecurityObjectType ObjectType { get; set; }
}
我的查询如下。正如您在Index
配置中看到的那样,我将属性映射Name
到DisplayName
但DisplayName
属性是null
返回文档时UserGroup
。当我查看获取的文档时Name
,属性未映射到DisplayName
属性,实际价值仍保留在Name
属性上。如何正确将该Name
属性转换为DisplayName
属性 on UserGroup
?
_session.Query<SecurityObject, SecurityObjectIndex>()
.Where(s => s.DisplayName.StartsWith(searchTerm))
.ProjectFromIndexFieldsInto<SecurityObject>();
这是我的索引配置:
public class SecurityObjectIndex
: AbstractMultiMapIndexCreationTask<SecurityObject>
{
public override string IndexName
{
get
{
return "UserAndUserGroup/SecurityObjectIndex";
}
}
public SecurityObjectIndex()
{
AddMap<User>(users => from u in users
select new
{
DisplayName = u.DisplayName,
ObjectType = SecurityObjectType.Users
});
AddMap<UserGroup>(userGroups => from u in userGroups
select new
{
DisplayName = u.Name,
ObjectType = SecurityObjectType.Groups
});
}
}