Indexing 变换过滤器
我有以下映射/变换Indexing 变换过滤器,indexing,mapreduce,ravendb,Indexing,Mapreduce,Ravendb,我有以下映射/变换 public class PositionSearch : AbstractIndexCreationTask<Employer> { public PositionSearch() { Map = employers => from employer in employers from position in employer.Positions se
public class PositionSearch : AbstractIndexCreationTask<Employer>
{
public PositionSearch()
{
Map = employers =>
from employer in employers
from position in employer.Positions
select new
{
EmployerName = employer.Name,
SearchSkills = position.RequiredSkills
.Select(x => x.Skill)
};
TransformResults = (database, results) =>
from result in results
from position in result.Positions
select new
{
EmployerId = result.Id,
EmployerName = result.Name,
PositionId = position.Id,
PositionTitle = position.Title,
RequiredSkills = position.RequiredSkills
.Select(x => new { x.Skill, x.Proficiency })
};
// Any field you are going to use .Search() on should be analyzed.
Index("SearchSkills", FieldIndexing.Analyzed);
}
}
公共类位置搜索:AbstractIndexCreationTask
{
公共位置搜索()
{
Map=雇主=>
从雇主到雇主
来自雇主的职位
选择新的
{
EmployerName=雇主名称,
SearchSkills=position.RequiredSkills
.选择(x=>x.Skill)
};
TransformResults=(数据库、结果)=>
从结果到结果
从结果中的位置。位置
选择新的
{
EmployerId=result.Id,
EmployerName=result.Name,
PositionId=position.Id,
PositionTitle=位置。标题,
RequiredSkills=职位。RequiredSkills
.选择(x=>新{x.技能,x.熟练程度})
};
//应该分析要在其上使用.Search()的任何字段。
索引(“SearchSkills”,FieldIndexing.analysis);
}
}
我有一个雇主对象,有两个职位,每个职位都有一项技能,“NH”和“MVC”
当我执行下面的查询时,我得到了两个返回的位置结果,而我预期的是一个。
谁能告诉我为什么会这样?我有一种感觉,这与我正在表演的一场比赛有关,但我不确定
using (var session = DocumentStore.OpenSession())
{
var results = session.Query<PositionSearchResultModel, PositionSearch>()
.Customize(x => x.WaitForNonStaleResults())
.Search(x => x.SearchSkills, "NH")
.OfType<PositionSearchResultModel>().ToList();
Assert.AreEqual(1, results.Count());
}
使用(var session=DocumentStore.OpenSession())
{
var results=session.Query()
.Customize(x=>x.WaitForNonSaleResults())
.Search(x=>x.SearchSkills,“NH”)
.OfType().ToList();
Assert.AreEqual(1,results.Count());
}
我想使用transform,以便访问临时索引分数元数据进行订购,到目前为止,没有transform,我无法访问元数据。您正在为
雇主
文档编制索引。搜索找到了一个包含相关技能的文档,然后您要求转换该文档
你得到它的方式是从索引中投影,这是你获得作为结果一部分的特定位置的唯一方式
我真的认为你会更喜欢位置
,因为它是自己的文档
public class Employer
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Position
{
public string Id { get; set; }
public string EmployerId { get; set; }
public string Title { get; set; }
public string Location { get; set; }
public ICollection<SkillProficiency> RequiredSkills { get; set; }
}
公共类雇主
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
}
公共阶级地位
{
公共字符串Id{get;set;}
公共字符串EmployerId{get;set;}
公共字符串标题{get;set;}
公共字符串位置{get;set;}
公共ICollection RequiredSkills{get;set;}
}
这在思维上似乎更具关联性,但在RavenDB中效果很好,而且查询起来比现在要容易得多。我已经从问题的标题中删除了标记。请看,非常感谢在您看来,对于我来说,使用非聚合根的文档并采用这种方法是否有意义。还是坚持从索引中投影再次感谢您抽出时间!我认为在你的例子中,
位置实际上是一个集合。你需要对它们进行单独的项目,这就证明了这一点。考虑<代码>订单< /代码>和<代码> OrthReals<代码> -您永远不会把<代码> OrthReals<代码>放在自己的文档中。如果按已排序的项目进行搜索,您仍然会返回整个订单
。但是你不是要找一个有职位的雇主,你是要找一个真正的职位。我想我只是觉得有几个灯泡亮了。非常感谢你的帮助希望我不需要在任何时候发布另一个问题!