Skip to content

Instantly share code, notes, and snippets.

@komainu85
komainu85 / Sitecore Search Configuration
Last active August 29, 2015 14:15
Custom search index configuration (Sitecore 7.2)
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<CustomSearchConrig>
<!-- INDEXING STRATEGIES
Here is a list of the different indexing strategies that you can use. You can also combine these strategies to achieve what you want.
-->
<indexUpdateStrategies>
<!-- INTERVAL BASED INDEX REBUILD STRATEGY FOR CORE DATABASE
@komainu85
komainu85 / Sitecore Image Url Computed Field
Created February 18, 2015 08:32
Sitecore Image Url Computed Field
public class ImageUrl : IComputedIndexField
{
public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
if (item != null)
{
var fileField = ((FileField)item.Fields["Image"];
@komainu85
komainu85 / IsStandardValue
Created February 18, 2015 20:53
IsStandardValue Sitecore Computed Field
public class IsStandardValue : IComputedIndexField
{
public object ComputeFieldValue(IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
return StandardValuesManager.IsStandardValuesHolder(item);
}
public string FieldName { get; set; }
@komainu85
komainu85 / Get Membership User From Sitecore Account
Created February 18, 2015 20:58
Get Membership User From Sitecore Account
public static class SitecoreAccountExtensions
{
public static MembershipUser GetMembershipUser(this Account account)
{
return Membership.GetUser(account.Name);
}
}
@komainu85
komainu85 / Sitecore Get Home Item Extension
Created February 18, 2015 21:06
Sitecore get home from SiteContext
public static Item HomeItem(this SiteContext site)
{
return Sitecore.Context.Database.GetItem(site.StartPath);
}
@komainu85
komainu85 / Sitecore Item Comparer
Created February 18, 2015 21:11
Sitecore Item Comparer
public class ItemComparer : IEqualityComparer<Item>
{
public bool Equals(Item x, Item y)
{
return x.ID == y.ID;
}
public int GetHashCode(Item obj)
{
return obj.ID.GetHashCode();
@komainu85
komainu85 / Sitecore Item Template Comparer
Created February 18, 2015 21:13
Sitecore Item Template Comparer
public class ItemTemplateComparer : IEqualityComparer<Item>
{
public bool Equals(Item x, Item y)
{
return x.TemplateID == y.TemplateID;
}
public int GetHashCode(Item obj)
{
return obj.TemplateID.GetHashCode();
@komainu85
komainu85 / Sitecore Expand Tokens
Created February 18, 2015 21:17
Sitecore Expand Tokens
Sitecore.Data.MasterVariablesReplacer replacer = Sitecore.Configuration.Factory.GetMasterVariablesReplacer();
Sitecore.Diagnostics.Assert.IsNotNull(replacer, "replacer");
replacer.ReplaceItem(item);
@komainu85
komainu85 / Sitecore Get Image URL with Dimensions
Created February 24, 2015 18:41
Sitecore Get Image URL with Dimensions
public static string GetImageUrl(this MediaItem mediaItem, int maxWidth = 0, int maxHeight = 0)
{
return GetMediaUrl(mediaItem) + CreateImageSizeQuery(maxWidth, maxHeight);
}
public static string GetMediaUrl(this MediaItem mediaItem)
{
var mediaUrl = MediaManager.GetMediaUrl(mediaItem);
return mediaUrl.Contains(MediaManager.MediaLinkPrefix)
@komainu85
komainu85 / Sitecore Content Search with Keywords
Created February 25, 2015 08:57
Sitecore Content Search with Keywords
public SearchResult<SearchItem> Search(string keywords)
{
using (var context = Sitecore.ContentSearch.ContentSearchManager.GetIndex(_searchIndex).CreateSearchContext())
{
var queryable = context.GetQueryable<SearchItem>();
Expression<Func<SearchItem, bool>> filters;
filters = GetKeywordFilters(keywords);
queryable = queryable.Where(filters);