我的文档结构如下:
Employer => Positions => RequiredSkills
雇主有一个职位集合
职位有一个RequiredSkill 集合。
所需技能由技能(字符串)和熟练程度(枚举)组成。
如果我使用动态索引,它似乎可以很好地返回公司,但是我想使用索引来填充 MVC 视图模型以返回 UI。
我对 Raven 真的很陌生,所以我很抱歉做了任何愚蠢/不必要的事情!
我有以下映射:
public class PositionSearch : AbstractIndexCreationTask<Employer>
{
public PositionSearch()
{
Map = employers =>
from employer in employers
from position in employer.Positions
select new
{
EmployerId = employer.Id,
EmployerName = employer.Name,
PositionId = position.Id,
PositionTitle = position.Title,
position.Location,
position.Description,
RequiredSkills = position.RequiredSkills
};
StoreAllFields(FieldStorage.Yes);
Index("RequiredSkills_Skill", FieldIndexing.Analyzed);
}
}
但是,当我尝试执行以下查询时:
var results = session.Query<PositionSearchResultModel, PositionSearch>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x=>x.RequiredSkills.Any(y=>y.Skill == "SkillName"))
.ProjectFromIndexFieldsInto<PositionSearchResultModel>()
.ToList();
我收到以下错误:
System.ArgumentException:
The field 'RequiredSkills_Skill' is not indexed,
cannot query on fields that are not indexed
谁能看到我做错了什么或为我建议另一种方法?
谢谢,
詹姆士
更新我的视图模型 - 谢谢:
public class PositionSearchResultModel
{
public PositionSearchResultModel()
{
RequiredSkills = new HashSet<SkillProficiency>();
}
public string EmployerId { get; set; }
public string EmployerName { get; set; }
public string PositionId { get; set; }
public string PositionTitle { get; set; }
public string Location { get; set; }
public string Description { get; set; }
public ICollection<SkillProficiency> RequiredSkills { get; set; }
}