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
public class MyCustomResolver : HttpRequestProcessor | |
{ | |
public override void Process(HttpRequestArgs args) | |
{ | |
// Return if Sitecore has found the item | |
if (Context.Item != null || Context.Database == null || args.Url.ItemPath.Length == 0) return; | |
// If item not found | |
var itemPath = args.Url.ItemPath; // The requested item path | |
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 Sitecore.Workflows.Simple; | |
namespace MyProject.Workflows | |
{ | |
public class CustomWorkflowAction | |
{ | |
public void Process(WorkflowPipelineArgs args) | |
{ | |
var workflowItem = args.DataItem; // The item in the workflow | |
// Custom logic here |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<contentSearch> | |
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch"> | |
<indexes hint="list:AddIndex"> | |
<index id="MySearchIndex" type="Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex, Sitecore.ContentSearch.LuceneProvider"> | |
<strategies hint="list:AddStrategy"> | |
<!-- NOTE: order of these is controls the execution order --> | |
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/intervalAsync3Hour" /> |
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
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<contentSearch> | |
<indexConfigurations> | |
<indexUpdateStrategies> | |
<intervalAsync3Hour type="Sitecore.ContentSearch.Maintenance.Strategies.IntervalAsynchronousStrategy, Sitecore.ContentSearch"> | |
<param desc="database">web</param> | |
<param desc="interval">03:00:00</param> | |
<CheckForThreshold>true</CheckForThreshold> | |
</intervalAsync3Hour> |
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
namespace MyProject | |
{ | |
/// <summary> | |
/// Index rendering/sublayout datasource | |
/// </summary> | |
public class IndexDataSource : IComputedIndexField | |
{ | |
/// <inheritdoc /> | |
public string FieldName { get; set; } | |
/// <inheritdoc /> |
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
private static Expression<Func<SearchModel, bool>> GetCategoryFacetPredicate(List<string> categories) | |
{ | |
var predicate = PredicateBuilder.True<SearchModel>(); // Items which meet the predicate | |
foreach (var category in categories) | |
{ | |
predicate = predicate.Or(x => x.Category == category); | |
} | |
return predicate; |
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
var searchIndex = ContentSearchManager.GetIndex("MySearchIndex"); // Get the search index | |
var searchPredicate = BuildSearchPredicate(searchRequest); // Build the search predicate | |
using (var searchContext = searchIndex.CreateSearchContext()) // Get a context of the search index | |
{ | |
var searchResults = searchContext.GetQueryable<SearchModel>().Where(searchPredicate); // Search the index for items which match the predicate | |
var searchFacets = searchContext.GetQueryable<SearchModel>().Where(searchPredicate).FacetOn(x => x.Category).GetFacets(); | |
// Category facets |
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
namespace MyProject.ComputedIndexFields | |
{ | |
/// <summary> | |
/// Index the main level section the item falls under | |
/// </summary> | |
public class IndexCategory : IComputedIndexField | |
{ | |
/// <inheritdoc /> | |
public string FieldName { get; set; } | |
/// <inheritdoc /> |
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
/// <summary> | |
/// Checks a list of content for the best match for a search term | |
/// </summary> | |
/// <param name="searchTerm">search term</param> | |
/// <param name="searchContent">search content</param> | |
/// <returns>Best match</returns> | |
private static string GetBestMatch(string searchTerm, List<string> searchContent) | |
{ | |
// create analyzer | |
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); |
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
/// <summary> | |
/// Highlight search term | |
/// </summary> | |
/// <param name="searchTerm">Search term</param> | |
/// <param name="searchContent">search content</param> | |
/// <returns>Search content with highlighted search term</returns> | |
private static string HighlightSearchTerm(string searchTerm, string searchContent) | |
{ | |
// create analyzer | |
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); |
NewerOlder