Created
October 31, 2016 14:40
-
-
Save timw255/cccdad20acbb9d1755af98197b9cca19 to your computer and use it in GitHub Desktop.
Helper methods to get additional information about items returned in Sitefinity search results.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Telerik.OpenAccess; | |
using Telerik.Sitefinity.Services.Search.Data; | |
using Telerik.Sitefinity.Taxonomies; | |
using Telerik.Sitefinity.Taxonomies.Model; | |
using Telerik.Sitefinity.Utilities.TypeConverters; | |
using Telerik.Sitefinity.Data; | |
using Telerik.Sitefinity.Model; | |
namespace SitefinityWebApp.Custom | |
{ | |
public class SearchResultHelper | |
{ | |
public static List<HierarchicalTaxon> Categories(IDocument result) | |
{ | |
var categories = new List<HierarchicalTaxon>(); | |
var typeString = result.GetValue("ContentType").ToString(); | |
var type = TypeResolutionService.ResolveType(typeString); | |
var manager = ManagerBase.GetMappedManager(typeString); | |
var item = manager.GetItem(type, Guid.Parse(result.GetValue("Id").ToString())) as IDynamicFieldsContainer; | |
var categoryIds = item.GetValue<TrackedList<Guid>>("Category"); | |
var taxonManager = TaxonomyManager.GetManager(); | |
categories.AddRange(taxonManager.GetTaxa<HierarchicalTaxon>().Where(t => categoryIds.Contains(t.Id)).ToList()); | |
return categories; | |
} | |
public static string ContentType(IDocument result) | |
{ | |
var type = TypeResolutionService.ResolveType(result.GetValue("ContentType").ToString()); | |
return type.Name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment