Hello,
We have a requirement to ensure that a property (Callsign) on a block is unique in our site.
We are currently inherting IValidate to allow us to validate the block and within the Validate method we use the method below to get all blocks of the same type so we can iterate over them and check the values accordingly to find if it already exists.
This works for the most part but if I create/edit two blocks in quick succession then the index doesnt appear to keep up and allows duplicates. If I wait around five minutes between edits all appears to work OK.
- Is it reasonable to expect the index to be realtime?
- Can I force a block to update the index when publishing to keep it in sync?
- Is there a better way to acheive unique values in EPiServer?
Snippet
public List<ILocalTeamMemberBlock> GetMatchingByCallSign(ILocalTeamMemberBlock block) { var search = SearchClient.Instance.Search<ILocalTeamMemberBlock>() .For(block.CallSign).InFields(x => x.CallSign) .Take(1000); try { var result = search.GetContentResult().ToList(); if (result.IsNullOrEmpty()) { IsError = true; return new List<ILocalTeamMemberBlock>(); } else { return result.ToList(); } } catch (Exception ex) { IsError = true; return new List<ILocalTeamMemberBlock>(); } }