Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to create a reduce index where an object key? #481

Open
MikeAlhayek opened this issue Mar 18, 2023 · 0 comments
Open

Is there a way to create a reduce index where an object key? #481

MikeAlhayek opened this issue Mar 18, 2023 · 0 comments

Comments

@MikeAlhayek
Copy link
Collaborator

@sebastienros It seems that the reduce index is works only with property member not an object. Is there a way to create a reduce index where an object key?

For example, this

       context.For<SearchQuerySummaryIndex, SomeKeyGroup>()
            .When(searchQuery => searchQuery.Has<SearchQueryResultPart>())
            .Map(searchQuery =>
            {
                var part = searchQuery.As<SearchQueryResultPart>();

                if (part.ContentItemIds == null || !part.ContentItemIds.Any())
                {
                    return null;
                }

                return part.ContentItemIds.Select(contentItemId => new SearchQuerySummaryIndex
                {
                    ContentItemId = contentItemId,
                    Count = 1,
                });
            }).Group(x => new SomeKeyGroup {
               ContentItemId = x.ContentItemId,
               AnotherProperty = x.AnotherProperty,
            })
            .Reduce(group => new SearchQuerySummaryIndex
            {
                ContentItemId = group.Key.ContentItemId,
                AnotherProperty  = group.Key.AnotherProperty .
                Count = group.Sum(p => p.Count)
            })
            .Delete((index, map) =>
            {
                index.Count -= map.Sum(p => p.Count);

                // if Count == 0 then delete the index
                return index.Count > 0 ? index : null;
            });

throws the following exception

Group expression is not a valid member of:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant