2
我有一些存储在RavenDb中的命令,它们都实现了ICommand。我希望能够搜索上次修改的元数据和Raven-Entity-Name。我目前做多地图上的每个命令如下:按实体名称和上次修改日期搜索
public class CommandAuditSearch_Index : AbstractMultiMapIndexCreationTask<CommandAuditSearch_Index.Results>
{
public class Results
{
public string CommandType { get; set; }
public DateTime LastModified { get; set; }
}
public CommandAuditSearch_Index()
{
AddMap<NewEmployeeStartCommand>(employees => employees.Select(x => new
{
CommandType = MetadataFor(x).Value<string>("Raven-Entity-Name"),
LastModified = MetadataFor(x).Value<DateTime>("Last-Modified")
}));
AddMap<EmployeeLeaverCommand>(employees => employees.Select(x => new
{
CommandType = MetadataFor(x).Value<string>("Raven-Entity-Name"),
LastModified = MetadataFor(x).Value<DateTime>("Last-Modified")
}));
Index(results => results.CommandType, FieldIndexing.Analyzed);
}
}
我查询这个如下:
session.Query<CommandAuditSearch_Index.Results, CommandAuditSearch_Index>()
.Where(x => x.CommandType == commandType && x.LastModified >= DateTime.Today).OfType<ICommand>().ToList();
我知道已经有内置乌鸦获得标签(实体名称索引)和最后修改日期,但我似乎无法弄清楚如何获得结果,因为我的指数上面给了我。
任何人都可以指向一个静态索引的正确方向,在这里我不需要像上面那样为每个我必须查询的命令提供多个映射,以ICommands列表的形式给出结果?
感谢
水稻
非常感谢这个马特。这正是我正在寻找的。我总是找到你的答案详细,并解释清楚。 – Paddy 2013-03-13 14:27:48