내가 같이이 문서에 정의 주어진 RavenDB 문서RavenDB 지수는 별개의
이상 필요 약간 복잡한 인덱스가 감소
012 :PricingDate
(최신) 다음과 같은 데이터를 제공
Source
그래서 의해 고유 이 (내가 쿼리 할 때 그렇게 할 수 있습니다)
var priceDocument = new PriceDocument {
Price = 1m,
Id = productId + "/1",
PricingDate = new DateTime(2011, 4, 1, 8, 0, 0),
PriceId = productId,
Source = "Bloomberg",
Version = 1
};
var priceDocument1 = new PriceDocument {
Price = 1m,
Id = productId + "/2",
PricingDate = new DateTime(2011, 4, 1,9,0,0),
PriceId = productId,
Source = "Bloomberg",
Version = 1
};
그 결과 최신 제품인 priceDocument1을 사용해야합니다.
가 지금까지 인덱스는 다음과 같이 정의 :
Map = docs =>
from priceDocument in docs
select new {
PricingDate = priceDocument.PricingDate,
PricingSource = priceDocument.Source,
Price = priceDocument.Price,
PriceId = priceDocument.PriceId
};
Reduce = results =>
from result in results
group result by new { result.PricingDate, result.Source } into price
select new {
PricingDate = price.Max(p => price.Key.PricingDate),
PricingSource = price.Key.Source,
};
그러나 런타임에 작업을 나던, 나는 AbstractIndexingExecuter||8||Failed to index documents for index (my index name)
과납니다
Cannot implicitly convert type 'System.DateTimeOffset' to 'int' changed the
DateTime?
toDateTime
그리고 운 : 나는 오류가 있음을 나는 까마귀 스튜디오에서 통계에 것을 볼 수 있습니다.
는 나는 이제 인덱스는 다음과 같습니다 증가에 의존 할 수있는 I를 사용하여 날짜를 사용하는 전환 :Map = docs =>
from priceDocument in docs
select new {
PricingDate = priceDocument.PricingDate,
PricingSource = priceDocument.Source,
ProductId = priceDocument.ProductId,
ProductVersion = priceDocument.Version
};
Reduce = results =>
from result in results
group result by new {
result.PriceId,
result.PricingDate,
result.Source,
result.Version
} into price
select new {
PricingDate = price.Key.PricingDate,
PricingSource = price.Key,
ProductVersion = price.Max(p=> price.Key.Version)
};
지금 그 오류가 발생하지 않습니다, 그러나 그것은 또한 어떤 결과를 제공하지 않습니다.
PricingDate = price.Max(p => (DateTimeOffset)price.Key.PricingDate)
을하지만, 당신이 원하는 아무튼 :
안녕하세요. 답변을 주셔서 감사합니다. 가격이 PriceDate와 PricingSource에서 고유해야합니다 (예 : 2 행을 포함 할 수 있습니다. 소스가 다른 한 동일한 날짜). 버전 (또는 날짜)이 가장 높은 버전을 선택하십시오. – roundcrisis
그러나 전체 답변은 아니지만 @ayende는 까마귀 토론 그룹 https://groups.google에서 질문에 답변했습니다. co.kr/d/topic/ravendb/B9HCmi32YWw/토론 및 솔루션은 https://gist.github.com/1186051 여기에 있습니다. – roundcrisis