C# RavenDB Map Reduce变换折叠一个不同的字符串列表
我的问题很短,我结巴了。我有一系列文件,如:C# RavenDB Map Reduce变换折叠一个不同的字符串列表,c#,linq,mapreduce,ravendb,C#,Linq,Mapreduce,Ravendb,我的问题很短,我结巴了。我有一系列文件,如: { ..., "Type": [ "Type1", "Type2", "Type3", "Type4" ], ... } 我认为我需要创建一个map/reduce索引,将这些值分组到字符串列表中,例如,如果我有以下两个文档: { ..., "Type": [ "Type1&qu
{
...,
"Type": [
"Type1",
"Type2",
"Type3",
"Type4"
],
...
}
我认为我需要创建一个map/reduce索引,将这些值分组到字符串列表中,例如,如果我有以下两个文档:
{
...,
"Type": [
"Type1",
"Type3"
],
...
}
{
...
"Type": [
"Type2",
"Type3",
"Type4"
],
...
}
我需要一个包含所有不同值的列表的结果,如{“Type1”、“Type2”、“Type3”、“Type4”}
我不知道怎么做,我试过几种方法,但都没有成功
我忘了说,我有大量的数据,现在有1500多个文档
public class ProjectTypeIndex : AbstractIndexCreationTask<Project, ProjectTypeIndex.ReduceResult>
{
public class ReduceResult
{
public string ProjectType { get; set; }
}
public ProjectTypeIndex()
{
Map = projects => from project in projects
select new
{
project.Type
};
Reduce = results => from result in results
group result by result.Type into g
select new
{
ProjectType = g.Key
};
}
}
公共类ProjectTypeIndex:AbstractIndexCreationTask
{
公共类ReduceResult
{
公共字符串项目类型{get;set;}
}
公共项目类型索引()
{
Map=projects=>来自projects中的project
选择新的
{
项目类型
};
Reduce=results=>from result in results
按结果分组结果。键入g
选择新的
{
ProjectType=g.Key
};
}
}
大家好,我找到了一个解决方案,但我不知道这是否是最好的方法,因为我仍然没有字符串列表,只有结果,我通过foreach填充字符串列表解决了这个问题,下面是索引创建。如果有人能检查代码,我将非常感激
public class ProjectTypeIndex : AbstractIndexCreationTask<Project, ProjectTypeIndex.ReduceResult>
{
public class ReduceResult
{
public string ProjectType { get; set; }
}
public ProjectTypeIndex()
{
Map = projects => from project in projects
from type in project.Type
select new
{
ProjectType = type
};
Reduce = results => from result in results
group result by result.ProjectType into g
select new
{
ProjectType = g.Key
};
}
}
公共类ProjectTypeIndex:AbstractIndexCreationTask
{
公共类ReduceResult
{
公共字符串项目类型{get;set;}
}
公共项目类型索引()
{
Map=projects=>来自projects中的project
来自项目中的类型。类型
选择新的
{
项目类型=类型
};
Reduce=results=>from result in results
按result.ProjectType将结果分组为g
选择新的
{
ProjectType=g.Key
};
}
}
是否只需要不同的值?您需要按soemthing对其进行分组吗?确切地说,我只想将类型列表上的不同值检索到文档中。我将用我编写的一些测试代码更新我的问题。谢谢你的快速回答。