Hi! Following on from yesterday's exciting post I'm back with another Examine question.
Is there a way to specify "Search for exactly this NodeName, don't return anything else unless it's exactly the same"? Found that searching "Article" would also give nodeNames like "Article About Umbraco" - which, while handy, isn't ideal for the use case of checking if a node called "Article" currently exists.
Code as is - goal is to only get a node with the NodeName as an exact match. To this end I've now added the extra if/foreach validation against the search result's "AllValues" dict, which feels cursed to say the least.
var folderSearchResult = index
.Searcher
.CreateQuery(Umbraco.Cms.Infrastructure.Examine.IndexTypes.Media)
.NodeTypeAlias(Folder.ModelTypeAlias)
.And()
.NodeName(nameOfFolder)
.And()
.ParentId(rootFolderId)
.Execute();
if (folderSearchResult != null)
{
foreach (var folderResult in folderSearchResult)
{
var nodeName = folderResult.AllValues["nodeName"].FirstOrDefault();
if (nodeName != null && nodeName.Equals(nameOfFolder))
{
return int.Parse(folderResult.Id);
}
}
}
TIA!