Skip to content

Instantly share code, notes, and snippets.

@komainu85
Last active September 10, 2015 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komainu85/3a6efad20ab1b2a56385 to your computer and use it in GitHub Desktop.
Save komainu85/3a6efad20ab1b2a56385 to your computer and use it in GitHub Desktop.
Sitecore Friendly URL Computed Field
using System.Xml;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.ComputedFields;
using Sitecore.Data.Items;
using Sitecore.Links;
using Sitecore.Xml;
namespace MikeRobbins.ContentSearch.ComputedFields
{
public class FriendlyUrl : AbstractComputedIndexField
{
public override object ComputeFieldValue(IIndexable indexable)
{
var scIndexable = indexable as SitecoreIndexableItem;
if (scIndexable != null)
{
var item = (Item)scIndexable;
if (item != null)
{
var opts = LinkManager.GetDefaultUrlOptions();
opts.Site = Sitecore.Sites.SiteContext.GetSite(SiteName);
return LinkManager.GetItemUrl(item, opts);
}
}
return null;
}
public FriendlyUrl()
{
}
public FriendlyUrl(XmlNode configurationNode) : this()
{
SiteName = XmlUtil.GetAttribute("siteName", configurationNode);
}
public string SiteName { get; set; }
}
}
<fields hint="raw:AddComputedIndexField">
<field fieldName="urllink" siteName="SiteName">MikeRobbins.ContentSearch.ComputedFields.FriendlyUrl,MikeRobbins.ContentSearch</field>
</fields>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment