Я все еще учусь, так что, возможно, моя модель в настоящее время неверна, но это то, что у меня есть:
Account
{
string Id,
string ArtistName,
List<FollowerAccount> Followers
}
FollowerAccount
{
AccountId,
DateBeganFollowing
}
Таким образом, документ моей Учетной записи содержит список денормализованных ссылок на список всех учетных записей, которые следуют за ними.
Теперь я хочу вернуть список учетных записей из списка подписчиков 'accounts / 1', но разместив их на странице, я знаю, что могу сделать это как 2 запроса, но я надеялся, что смогу зафиксировать этот запрос 2 1.
Вот индекс, с которым я играюсь, однако я не могу заставить его работать.
public class TestIndex : AbstractMultiMapIndexCreationTask<TestIndex.ReduceResult>
{
public class ReduceResult
{
public string AccountId { get; set; }
public DateTimeOffset? DateBecameFollower { get; set; }
public string ParentAccountId { get; set; }
public string ArtistName { get; set; }
}
public TestIndex()
{
AddMap<Account>(followers => from follower in followers
from sub in follower.FollowersAccounts
select new
{
ParentAccountId = follower.Id,
AccountId = sub.AccountId,
DateBecameFollower = sub.DataBecameFollower,
ArtistName = (string)null
});
AddMap<Account>(accounts => from account in accounts
select new
{
ParentAccountId = (string)null,
AccountId = account.Id,
DateBecameFollower = DateTimeOffset.MinValue,
ArtistName = account.ArtistName,
});
Reduce = results => from result in results
group result by result.AccountId
into g
select new
{
ParentAccountId = g.Select(x => x.ParentAccountId).Where(x => x != null).First(),
AccountId = g.Key,
DateBecameFollower = g.Select(x => x.DateBecameFollower).Where(x => x != DateTimeOffset.MinValue).First(),
ArtistName = g.Select(x => x.ArtistName).Where(x => x != null).First()
};
}
}