jacksorjacksor (Richard Jackson)
09/13/2023, 11:40 AMvar 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!Jason
09/13/2023, 3:59 PMjacksorjacksor (Richard Jackson)
09/13/2023, 4:19 PMjacksorjacksor (Richard Jackson)
09/13/2023, 9:05 PMcsharp
public IPublishedContent? GetBlogArticleFolder()
{
var rootFolder = UmbracoHelper.MediaAtRoot().FirstOrDefault(x => x is { Name: "Blog", ContentType: Folder.GetModelContentType(_publishedSnapshotAccessor) });
return rootFolder?.Descendants<Folder>().FirstOrDefault(x => x.Name is "Article Name To Find");
}
Would this be the correct way to find the child of a media item called "Blog" which is a folder called "BlogName"?Sebastiaan
09/14/2023, 6:59 AMcsharp
after the first 3 backticks you get nice code highlighting? 😁jacksorjacksor (Richard Jackson)
09/14/2023, 7:12 AMJason
09/14/2023, 8:29 AMis
nzdev
09/14/2023, 8:51 AMMike Chambers
09/14/2023, 9:14 AMcsharp
.CreateQuery(Umbraco.Cms.Infrastructure.Examine.IndexTypes.Media)
.NodeTypeAlias(Folder.ModelTypeAlias)
.And()
.NodeName(nameOfFolder.ToLower().Escape())
.And()
.ParentId(rootFolderId)
.Execute();
if you look at the query generated from
.Field("someField", "Article Name To Find")
it actually ends up being somefield is "article" or "name" or "to" or "find" due the the fluent examine parsing? or just examine itself
nodeName is already a raw field I think so Escape()
should work for the phrase matching but if you needed it for other fields..Mike Chambers
09/14/2023, 9:15 AMJason
09/14/2023, 10:49 AMnodeName
isn't a raw @Mike Chambers
In the case of two nodes:
1: "Page"
2: "Another Page"
NodeName("page".Escape())
will return both.
Adding other/extra raw fields though is a great way to look up things like product SKUs, exact name etc. or pulling content from anywhere on the tree based on a property value (you can actually mimic one-to-many/one relationships using examine to do a reverse lookup, which is really cool.)Mike Chambers
09/14/2023, 11:02 AMurlName
, or does another-page
still get tokenised with - as a delimeter?Jason
09/14/2023, 11:45 AMadi_yaish
09/28/2023, 7:22 AMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by