Skip to content

Instantly share code, notes, and snippets.

@neilkillen
Last active April 23, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilkillen/2cc341af7eaebf08f8a262a43f5c12bd to your computer and use it in GitHub Desktop.
Save neilkillen/2cc341af7eaebf08f8a262a43f5c12bd to your computer and use it in GitHub Desktop.
protected virtual ItemModel DoSearch(object value, Plugins.ResolveSitecoreItemEnhancedSettings resolveItemSettings, IItemModelRepository repository, ILogger logger, PipelineContext pipelineContext)
{
if (!(GetValueReader(resolveItemSettings.MatchingFieldValueAccessor) is SitecoreItemFieldReader sitecoreItemFieldReader))
{
Log(
logger.Error,
pipelineContext,
"The matching field value accessor is not a valid Sitecore item field reader.");
return null;
}
string text = ConvertValueForSearch(value);
Log(
logger.Debug,
pipelineContext,
"Value converted for search.",
$"field: {sitecoreItemFieldReader.FieldName}",
$"original value: {value}",
$"converted value: {text}");
Log(
logger.Debug,
pipelineContext,
"Starting search for item.",
$"field: {sitecoreItemFieldReader.FieldName}",
$"value: {text}");
IEnumerable<ItemModel> enumerable = repository.Search(new ItemSearchSettings
{
SearchFilters =
{
new SearchFilter
{
FieldName = sitecoreItemFieldReader.FieldName,
Value = text
},
new SearchFilter
{
FieldName = "TemplateID",
Value = resolveItemSettings.TemplateForNewItem.ToString()
}
}
});
return enumerable?.FirstOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment