RavenDB索引中的奇怪日期格式

时间:2012-02-22 22:28:04

标签: mapreduce ravendb

我在索引中使用日期格式时遇到了一些麻烦。他们是 序列化为不可序列化的东西。我们的实体有这个 形状:

  [Serializable] 
  public class Publication 
  { 
    public Guid? Id { get; set; } 
    public PublicationRendering Rendering { get; protected internal set; } 
    public DateRange SuggestedActiveRange { get; protected set; } 
    public DateRange ActualActiveRange { get; protected internal set; } 
    ... 
  } 
  public class DateRange 
  { 
    public DateTime StartDate { get; private set; } 
    public DateTime? EndDate { get; set; } 
    ... 
  } 

文档已正确序列化:

publications/806059ce-fd7a-4655-8e0e-9fff00f5ebd3 
{ 
  ... 
  "SuggestedActiveRange": { 
    "StartDate": "2011-11-22T00:00:00.0000000Z", 
    "EndDate": "2012-01-22T00:00:00.0000000Z", 
    "TimeSpan": "61.00:00:00" 
  }, 
  "ActualActiveRange": { 
    "StartDate": "2011-11-22T00:00:00.0000000Z", 
    "EndDate": "2012-01-22T00:00:00.0000000Z", 
    "TimeSpan": "61.00:00:00" 
  }, 
  ... 
} 

我正在定义我的索引(这是一个多减少):

  public class PublishedPolicyIndex : 
    AbstractMultiMapIndexCreationTask<PublishedPolicyIndex.ReduceResult> 
  { 
    public PublishedPolicyIndex() { 
      AddMap<Publication>(publications => publications.Select(publication => new { 
        ArtifactId = "artifacts/" + publication.Rendering.ArtifactId, 
        ActiveStartDate = publication.ActualActiveRange.StartDate, 
        ActiveEndDate = publication.ActualActiveRange.EndDate, 
        ViewingPrincipals = (string[]) null, 
        ... 
      })); 
      AddMap<Artifact>(artifacts => artifacts.Select(artifact => new { 
        ArtifactId = artifact.Id, 
        ActiveStartDate = (string) null, 
        ActiveEndDate = (string) null, 
        artifact.ViewingPrincipals, 
        ... 
      })); 
      Reduce = results => results.GroupBy(result => result.ArtifactId).Select(g => new { 
        ArtifactId = g.Key, 
        ActiveStartDate = g.Select(x => x.ActiveStartDate).SingleOrDefault(x => x != null), 
        ActiveEndDate = g.Select(x => x.ActiveEndDate).SingleOrDefault(x => x != null), 
        ViewingPrincipals = g.Select(x => x.ViewingPrincipals).SingleOrDefault(x => x != null), 
        ... 
      }); 
      Analyzers = new Dictionary<Expression<Func<ReduceResult, object>>, string> { 
        {rr => rr.ActiveStartDate, "Lucene.Net.Analysis.Standard.StandardAnalyzer"}, 
        {rr => rr.ActiveEndDate, "Lucene.Net.Analysis.Standard.StandardAnalyzer"}, 
        ... 
      }; 
      Stores.Add(x => x.ActiveStartDate, FieldStorage.Yes); 
      Stores.Add(x => x.ActiveEndDate, FieldStorage.Yes); 
    } 
    public class ReduceResult : IReduceResults 
    { 
      public string ArtifactId { get; set; } 
      public string ActiveStartDate { get; set; } 
      public string ActiveEndDate { get; set; } 
      public string[] ViewingPrincipals { get; set; } 
      ... 
    } 
  } 

但是当我查看我的索引时,我有这些数据:

{ 
  "ArtifactId": "artifacts/533b8cba-8b8f-4c23-b89a-9fff00f5ebd3", 
  "ActiveStartDate": "20111122000000000", 
  "ActiveEndDate": "20120322000000000", 
  "ViewingPrincipals": [ 
    "b0202923-eb07-493d-a0b5-9fff00f5ebd3" 
  ], 
  ... 
} 

这几乎就像是在散列这些日期。也许我没有设置 我的田间存储正确吗?如果我显式调用.ToString(“u”),它 将以可反序列化的格式存储日期,但不是 非常等于我想要的格式,加上太乱了。

0 个答案:

没有答案