Hi!
I am trying to run a query against a multinode treepicker property to get all documents where the current node is picked in the treepicker.
However currently the query is returning all documents which contain any value, instead of just those which contain the current documents GUID.
Here is my current code:
var currentPage = umbracoContext?.PublishedRequest?.PublishedContent;
// Get the ID of the current page and convert it to UDI
var currentNodeUdi = currentPage != null ? Udi.Create(Constants.UdiEntityType.Document, currentPage.Key).ToString() : string.Empty;
// Use the provided UmbracoHelper instance
var umbracoHelper = Umbraco;
IEnumerable
projectArticles = Enumerable.Empty
();
if (!string.IsNullOrEmpty(currentNodeUdi) && examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index))
{
// Use the default searcher provided by Examine
var searcher = index.Searcher;
var query = searcher.CreateQuery("content").NodeTypeAlias("projectArticle")
.And().Field("nodeConnection", $"\"{currentNodeUdi}\""); // Manually adding quotes around the UDI
var searchResults = query.Execute();
projectArticles = searchResults.Select(x => umbracoHelper.Content(x.Id))
.Where(x => x != null)
.Cast
(); // Ensure all items are non-nullable IPublishedContent