.net RavenDB:如何使用多贴图/减少索引
我有一个非常简单的模型:.net RavenDB:如何使用多贴图/减少索引,.net,nosql,mapreduce,ravendb,.net,Nosql,Mapreduce,Ravendb,我有一个非常简单的模型: public class PhraseMeta: { public int Id { get; set; } public string ModuleName { get; set; } public string Description { get; set; } public DateTime ModifiedDate { get; set; } } public class Phrase { public int Id { get; set; }
public class PhraseMeta:
{
public int Id { get; set; }
public string ModuleName { get; set; }
public string Description { get; set; }
public DateTime ModifiedDate { get; set; }
}
public class Phrase
{
public int Id { get; set; }
public int PhraseMetaId { get; set; } //reference to PhraseMeta
public string Language { get; set; }
public string Text { get; set; }
}
短语包含一些翻译,而PhraseMeta具有多个短语的元信息。
我试图找到短语的文本具有模块名称和语言。
据我所知,RavenDB的Multi-Maps/Reduce indexes功能可以帮助解决这个问题,而不是使用WhereEntityIs。
我的索引是:
public class PhraseEntry
{
public string MetaId { get; set; }
public string ModuleName { get; set; }
public string Language { get; set; }
public string Text { get; set; }
}
public class PhraseTranslationIndex : AbstractMultiMapIndexCreationTask<PhraseEntry>
{
public PhraseTranslationIndex()
{
this.AddMap<PhraseMeta>(phraseMetas => from pm in phraseMetas
select new
{
MetaId = pm.Id,
ModuleName = pm.ModuleName,
Language = (string)null,
Text = (string)null
});
this.AddMap<Phrase>(phrases => from phrase in phrases
select new
{
MetaId = phrase.PhraseMetaId,
ModuleName = (string)null,
Language = phrase.Language,
Text = phrase.Text
});
this.Reduce = results => from entry in results
group entry by entry.MetaId
into g
select new
{
MetaId = g.Key,
ModuleName = g.Select(x => x.ModuleName).Where(x => x != null).First(),
Language = g.Select(x => x.Language).Where(x => x != null).First(),
Text = g.Select(x => x.Text).Where(x => x != null).First()
};
this.Index(x => x.ModuleName, FieldIndexing.Analyzed);
this.Index(x => x.Language, FieldIndexing.Analyzed);
this.Index(x => x.Text, FieldIndexing.Analyzed);
}
}
公共类短语条目
{
公共字符串元ID{get;set;}
公共字符串ModuleName{get;set;}
公共字符串语言{get;set;}
公共字符串文本{get;set;}
}
公共类短语翻译索引:AbstractMultiMapIndexCreationTask
{
公共短语翻译索引()
{
this.AddMap(phraseMetas=>来自phraseMetas中的pm
选择新的
{
MetaId=pm.Id,
ModuleName=pm.ModuleName,
语言=(字符串)null,
Text=(字符串)null
});
this.AddMap(短语=>来自短语中的短语
选择新的
{
MetaId=短语.phraseMetId,
ModuleName=(字符串)null,
语言=短语。语言,
Text=短语。Text
});
this.Reduce=results=>来自results中的条目
按条目分组条目。MetaId
进入g
选择新的
{
MetaId=g.键,
ModuleName=g.Select(x=>x.ModuleName)。其中(x=>x!=null)。First(),
Language=g.Select(x=>x.Language)。其中(x=>x!=null)。First(),
Text=g.Select(x=>x.Text)。其中(x=>x!=null)。First()
};
Index(x=>x.ModuleName,FieldIndexing.Analyzed);
这个.Index(x=>x.Language,fieldindex.Analyzed);
这个.Index(x=>x.Text,fieldindex.analysis);
}
}
这就是我试图使用它的方式:
var entry = documentSession.Query<PhraseEntry, PhraseTranslationIndex>
.Where(p => p.ModuleName == "MyModule")
.Where(p => p.Language == "en")
.FirstOrDefault();
var entry=documentSession.Query
.Where(p=>p.ModuleName==“MyModule”)
.其中(p=>p.语言==“en”)
.FirstOrDefault();
这个指数没有结果。我正在使用Build472
有什么想法吗?问题可能是您正在使用First(),尝试使用FirstOrDefault()也许最好在邮件列表1中询问。管理工作室怎么说?2.你能看到这个索引吗?它在ManagementStudio中是否有错误?3.相同指数但不减少的结果是什么?4.可能是First()失败了吗?尝试g.Select(x=>x.Text)。管理工作室说:“序列不包含任何元素”;2.是的,我可以看到这个索引,但它只显示第一个map和reduce函数。没有第二个映射函数。映射函数似乎正在工作:我可以看到短语条目的“原始”数据(Count是短语元数+短语数)。