Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marc Love (uSkinned.net) 447 posts 1790 karma points
    Jun 22, 2022 @ 11:24
    Marc Love (uSkinned.net)
    1

    Examine, Transforming index values in V10

    Anyone know how to transform your Examine index in V10?

    A breaking change was introduced which makes ValueSet immutable.

    TryAdd to add new items to index no longer works. The documentation still claims it can be used:

    https://our.umbraco.com/documentation/reference/searching/examine/examine-events#adding-the-path-of-the-node-as-a-searchable-field-into-the-index

    However you can see the breaking change here:

    https://github.com/umbraco/Umbraco-CMS/pull/12307

    Cheers,

    Marc

  • Patrick de Mooij 73 posts 623 karma points MVP 3x c-trib
    Jun 22, 2022 @ 12:25
    Patrick de Mooij
    105

    Also notified you on Slack, but this way other people can also find the answer to this question.

    With Examine v3, it seems like you'll have to convert the values to a dictionary, add/change values and then set the valueset against the event arguments.

    You can see this being used in the tests that are present in the Examine v3 code base: https://github.com/Shazwazza/Examine/blob/release/3.0/src/Examine.Test/Examine.Lucene/Index/LuceneIndexTests.cs#L328

  • Marc Love (uSkinned.net) 447 posts 1790 karma points
    Jun 22, 2022 @ 13:06
    Marc Love (uSkinned.net)
    6

    Just to add to this, you need to use SetValues to update the index:

    var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());
    updatedValues.Add("YOURKEY",new List<object> { "YOURVALUE" });
    e.SetValues(updatedValues.ToDictionary(x => x.Key, x => (IEnumerable<object>)x.Value));
    
  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Jul 20, 2022 @ 14:24
    Owain Williams
    1

    Thanks for sharing Marc, just ran in to this issue myself today.

    h5yr

    O.

  • Lee 1130 posts 3088 karma points
    Jan 15, 2023 @ 07:43
    Lee
    0

    I cannot get this working in V11. The e.SetValues() does not save the new items. And when I hit save again, the previously added items are added again. Here is my code

    https://our.umbraco.com/forum/using-umbraco-and-getting-started//110908-unable-to-get-an-examine-custom-index-item-to-work-in-v11

    Can anyone point me in the right direction?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies