我的问题很短暂,我坚持下去。我有一系列文件,如:
{
...,
"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
};
}
}
答案 0 :(得分:2)
大家好我发现了一个解决方案,但我不知道是否是最好的方法,因为我仍然没有字符串列表只有结果,我解决了它通过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
};
}
}