我有一個文件結構如下所示: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