Re: [RavenDB] Issue querying an Index with TranformResults

26 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Aug 11, 2012, 12:58:48 PM8/11/12
to rav...@googlegroups.com
The where clause it applied to the _Map_ result, the TransformResults happens _after_ you have gotten the results.

On Fri, Aug 10, 2012 at 6:40 PM, DanielSan <d...@aqueduct.co.uk> wrote:
Below is the query and index I have for retrieving fixtures for a given team (home or away). However the where clause is being completely ignored. How can I do this?

Query:
var teamResults = session.Query<FixtureTeams, Results_BySeason>()
                .Where(result => result.HomeTeamId == teamId || result.AwayTeamId == teamId)
                .As<FixtureTeams>()
                .Lazily();

Index:
public class Results_BySeason : AbstractIndexCreationTask<Season>
{
        public Results_BySeason()
{
Map = seasons => from season in seasons
                from stage in season.Stages
                from @group in stage.Groups
                from fixture in @group.Fixtures
                select new
                        {
                                            season.Id
                                            season.CompetitionName,
                                            GroupId = @group.Id,
                                            FixtureId = fixture.Id,
                                            fixture.HomeTeamId,
                                            fixture.AwayTeamId,
                                            fixture.HomeFullTimeScore,
                                            fixture.AwayFullTimeScore,
                        };

            TransformResults = (database, seasons) => from season in seasons
                                                      from stage in season.Stages
                                                      from @group in stage.Groups
                                                      from fixture in @group.Fixtures
                                                      let homeTeam = database.Load<Team>("teams/" + fixture.HomeTeamId)
                                                      let awayTeam = database.Load<Team>("teams/" + fixture.AwayTeamId)
                                                      select new {
                                                                season.Id,
                                                                season.CompetitionId,
                                                                season.CompetitionName,
                                                                fixture.ResultType,
                                                                GroupId = @group.Id,
                                                                FixtureId = fixture.Id,
                                                                fixture.HomeTeamId,
                                                                fixture.AwayTeamId,
                                                                fixture.HomeFullTimeScore,
                                                                fixture.AwayFullTimeScore, 
                                                                HomeTeamName = homeTeam.Name,
                                                                AwayTeamName = awayTeam.Name
                                                            };
        }
}

DanielSan

unread,
Aug 13, 2012, 7:24:26 AM8/13/12
to rav...@googlegroups.com
Ok, so how would recommend querying this index lazily?

I.E. Not converting to a standard IEnumerable linq query:

var teamResults = session.Query<FixtureTeams, Results_BySeason>().ToList()
                .Where(result => result.HomeTeamId == teamId || result.AwayTeamId == teamId);

Oren Eini (Ayende Rahien)

unread,
Aug 13, 2012, 7:26:52 AM8/13/12
to rav...@googlegroups.com
I don't understand your question.
var teamResults = session.Query<FixtureTeams, Results_BySeason>()
                .Where(result => result.HomeTeamId == teamId || result.AwayTeamId == teamId)
                .ToList();

Kijana Woodard

unread,
Aug 13, 2012, 9:12:21 AM8/13/12
to rav...@googlegroups.com

The transform results happens on the server at query time. Is that what you mean by lazy?

Map and reduce happen at index time.

Reply all
Reply to author
Forward
0 new messages