我有一个文件结构如下所示:RavenDb静态指标:在孩子收集查询对象
Employer => Positions => RequiredSkills
发包方位置
位置有RequiredSkill集合的集合。
必需技能由技能(字符串)和熟练(枚举)组成。
如果我使用动态索引它似乎返回公司罚款,但是我想使用索引来填充MVC视图模型返回到用户界面。
我真的很新来乌鸦,所以我很抱歉做任何愚蠢/不必要的事!
我有以下映射:
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; }
}
您将索引条目与索引结果混淆。请提供您的'PositionSearchResultModel'类,我将回答一个完整的解决方案。谢谢。 – 2013-02-12 15:00:45
添加了我的视图模型。 – Jamez 2013-02-12 15:10:17
我看到你试图标记分析的领域。你想要在技能名称上完全匹配吗?或者你想进行分析搜索? – 2013-02-12 15:41:16