Skip to content

Allow mix of single objects and enumerables in valueset#340

Merged
Shazwazza merged 4 commits intoShazwazza:release/4.0from
andrewmckaskill:4.0-valueset-enumerable
Aug 23, 2023
Merged

Allow mix of single objects and enumerables in valueset#340
Shazwazza merged 4 commits intoShazwazza:release/4.0from
andrewmckaskill:4.0-valueset-enumerable

Conversation

@andrewmckaskill
Copy link

@andrewmckaskill andrewmckaskill commented Jul 5, 2023

This change updates the yield helper method that converts an IDictionary<string, object> to an IDictionary<string, IEnumerable<object>>.

This allows for greater flexibility when constructing valueSets. Currently, if you have a single field that requires multiple values (say for faceting), you must use the IDictionary<string, IEnumerable<object>> overload and wrap all your fields in arrays or other enumerable structures. This change means that you can submit an array for a field and it will be automatically interpreted correctly.

Before - with all other fields wrapped in arrays:

var multiValues = new Dictionary<string, IEnumerable<object>>
{
    // this is a special field used to display the content name in the Examine dashboard
    [UmbracoExamineFieldNames.NodeNameFieldName] = new[] { content.Name! },
    // add the fields you want in the index
    ["id"] = new List<object> { content.Id },
    ["udi"] = new[] { content.GetUdi() },
    ...
    // GetTags returns an array of tags
    ["tags"] = GetTags(content)
};

After - with mix of single objects and arrays:

var indexValues = new Dictionary<string, object>
{
    // this is a special field used to display the content name in the Examine dashboard
    [UmbracoExamineFieldNames.NodeNameFieldName] = content.Name!,
    // add the fields you want in the index
    ["id"] = content.Id,
    ["udi"] = content.GetUdi(),
    ...
   // GetTags return an array of tags
    ["tags"] = GetTags(content),
};

@andrewmckaskill andrewmckaskill changed the base branch from release/3.0 to release/4.0 July 5, 2023 09:01
@Shazwazza
Copy link
Owner

I like the idea. Are you able to add a unit test for this and/or integration tests in the LuceneIndexTests?

@andrewmckaskill
Copy link
Author

I like the idea. Are you able to add a unit test for this and/or integration tests in the LuceneIndexTests?

Sure - let me take a look at it today.

@nikcio
Copy link
Contributor

nikcio commented Jul 26, 2023

@andrewmckaskill This PR currently has merge conflicts could I get you to rebase or merge release/4.0 into your branch? 😄
This is properly in response to the addition of nullables in the Examine project so please use the appropriate nullable modifiers for your addition.

@andrewmckaskill
Copy link
Author

@nikcio No it was just a simple conflict in the import statements. I've gone ahead and rebased on top of current release/4.0 branch for you to make the history clean.

The only change in this PR is the extra logic inside the Yield method to deal with Enumerables. I can't see VS complaining about any nullable items in that method, so I think it's good to go.

@andrewmckaskill andrewmckaskill force-pushed the 4.0-valueset-enumerable branch from db2fadb to b31fe58 Compare August 10, 2023 14:54
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

Successfully merging this pull request may close these issues.

3 participants