#Umbraco don't take my custom ISearchableTree
1 messages · Page 1 of 1 (latest)
Code
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.ContentEditing;
namespace Umbraco.Trees
{
public class FavouriteeThingsTree : Umbraco.Cms.Core.Trees.ISearchableTree
{
public string TreeAlias => "favouriteeThingsAlias";
public async Task<EntitySearchResults> SearchAsync(string query, int pageSize, long pageIndex, string searchFrom = null)
{
// your custom search implementation starts here
Dictionary<int, string> favouriteThings = new Dictionary<int, string>
{
{ 1, "Raindrops on Roses" },
{ 2, "Whiskers on Kittens" },
{ 3, "Skys full of Stars" },
{ 4, "Warm Woolen Mittens" },
{ 5, "Cream coloured Unicorns" },
{ 6, "Schnitzel with Noodles" }
};
var searchResults = new List<SearchResultEntity>();
var matchingItems = favouriteThings.Where(f => f.Value.StartsWith(query, true, System.Globalization.CultureInfo.CurrentCulture));
foreach (var matchingItem in matchingItems)
{
// Making up the Id/Udi for this example! - these would normally be different for each search result.
searchResults.Add(new SearchResultEntity()
{
Id = 12345,
Alias = "favouriteThingItem",
Icon = "icon-favorite",
Key = new Guid("325746a0-ec1e-44e8-8f7b-6e7c4aab36d1"),
Name = matchingItem.Value,
ParentId = -1,
Path = "-1,12345",
Score = 1.0F,
Trashed = false,
Udi = Udi.Create("document", new Guid("325746a0-ec1e-44e8-8f7b-6e7c4aab36d1"))
});
}
// Set number of search results found
var totalFound = matchingItems.Count();
// Return your results
return new EntitySearchResults(searchResults, totalFound);
}
}
}
Any?
please
And i've tried to register the ISearchableTree into the IComposer, without effect
Hi,
Just had a look and i don't know when it changed in the code, but i think your ISearchableTree implimentation now needs to be on a TreeController.
I had a searchable tree that use to work, but now like yours it doesn't look like its getting hit, I moved the implimentation to the tree controller (so added it to an existing tree controller move the methods). and now it gets hit on search 🤷♀️
Thanks you! Can you send me an exemple of the code ?