Skip to content

Instantly share code, notes, and snippets.

@vince-geekcore
vince-geekcore / GenerateHighlightText.cs
Last active August 29, 2015 14:28
Lucene.NET HitHighlighter (with Boolean Query) could be used in combination with Sitecore.
/// <summary>
/// Uses Lucene Contrib Highlighter to create search highlight based on an index field/string with all content
/// This code requires Lucene 3.0.3.0 DLL from Nuget and is not supported with the Sitecore7 Lucene DLL out of the box.
/// This is pure Lucene code and does not use any Sitecore namespaces.
/// Adding Try/catch is advised. searchQuery = searchterm/keyword(s)
/// </summary>
private string GenerateHighlightText(string pageContent, string searchQuery)
{
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
// Create Wildcard query using the BooleanQuery for multiple words.
@vince-geekcore
vince-geekcore / GetAllItemsBasedOnRendering.cs
Last active August 29, 2015 14:28
Use Sitecore Content Search (Lucene) Index to retrieve all items from index that include a specific rendering. Don't forget to allow/include "__Renderings" in your index. Cleaner solution could be achieved using ComputedField to index renderings by ID type (for example)
/// <summary>
/// Use Sitecore Content Search (Lucene) Index to retrieve all items from index that include a specific rendering
/// </summary>
/// <param name="templateID"></param>
/// <param name="database"></param>
/// <param name="indexName"></param>
/// <returns></returns>
private List<Item> GetAllItemsBasedOnRendering(ID renderingID, string database, string indexName)
{
List<Item> resultList = new List<Item>();
@vince-geekcore
vince-geekcore / sitecreator.cs
Last active September 3, 2015 13:49
Create an IIS binding using the MS ServerManager (Microsoft.Web.Administration namespace)
/// <summary>
/// Create an IIS binding. Warning: Sitecore will pickup the IIS
/// change and will restart when this code is executed!
/// </summary>
/// <returns></returns>
public void CreateIISBinding()
{
ServerManager iisManager = new ServerManager();
Site site = iisManager.Sites[Properties.Settings.Default.IISInstanceName];
string binding = string.Format(@"{0}:{1}:{2}", "*", "80", this.HostName);
@vince-geekcore
vince-geekcore / contentsearch-example.cs
Last active September 4, 2015 09:04
Sitecore ContentSearch example
/// <summary>
/// Get Searchresults with keyword overload for Global Search
/// </summary>
/// <typeparam name="U"></typeparam>
/// <param name="context"></param>
/// <param name="language"></param>
/// <param name="filters"></param>
/// <param name="unfilteredFacets"></param>
/// <param name="applyFacets"></param>
/// <param name="keyword"></param>
@vince-geekcore
vince-geekcore / ContentSearch.CustomIndex.config
Last active February 24, 2016 21:17
Sitecore 8.1 custom index configuration example for web db. To be placed in \app_config\include\customer-folder. Depends on a custom BaseConfiguration file
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="yourcustom_indexname" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<!-- This initializes index property store. Id has to be set to the index id -->
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
@vince-geekcore
vince-geekcore / ContentSearch.CustomIndexBaseConfiguration.config
Created February 24, 2016 21:22
Sitecore 8.1 ContentSearch Base Configuration file (to be referenced in index configuration)
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<!-- If no configuration is specified for an index, it uses the default configuration. The configurations are not merged if the index also has a
configuration. The system uses either the default configuration or the index configuration. -->
<CustomIndexBaseConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<!-- This flag will index all fields by default. This allows new fields in your templates to automatically be included into the index.
You have two choices :
@vince-geekcore
vince-geekcore / Sitecore Blobtransfer code
Last active November 22, 2016 21:56
This code was used in a one-time migration script on Sitecore 7.2 (2014) // Parts are supplied by Sitecore.Support. No guarantees ;) // More context can be found here http://www.geekcore.nl/sitecore/extreme-sitecore-migration/
// This code was used in a one-time migration script on Sitecore 7.2 (2014)
// Parts are supplied by Sitecore.Support. No guarantees ;)
// More context can be found here http://www.geekcore.nl/sitecore/extreme-sitecore-migration/
public class TransferMedia
{
public Sitecore.Data.Database migration
{
get
{
@vince-geekcore
vince-geekcore / ee-warmup.js
Last active January 29, 2023 12:21
Sitecore Experience Editor 8.2-2 compatible warmup PhantomJS script to be triggered using Powershell (for example as Azure WebJob). Based on PhantomJS because it's already available on Sitecore 8 environments. Some paths are currently still hardcoded for webapps
var page = new WebPage(), testindex = 0, loadInProgress = false;
var args = require('system').args;
var host = args[1];
var username = args[2];
var password = args[3];
var pageEditorUrl = args[4];
var token;
var system = require('system');
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;