Skip to content

Instantly share code, notes, and snippets.

View fluxdigital's full-sized avatar

Adam Seabridge fluxdigital

View GitHub Profile
@fluxdigital
fluxdigital / Feature.BlogPostSearch.Index.Web.config
Last active September 16, 2022 00:34
Config for Blog Post index
<?xml version="1.0" encoding="utf-8" ?>
<configuration
xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/"
xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore role:require="Standalone or ContentManagement or ContentDelivery" search:require="solr">
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="sc93_blogs_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
@fluxdigital
fluxdigital / Blog Post Search Results View
Created September 16, 2022 00:00
BlogPostSearchResults.cshtml
@using Glass.Mapper.Sc.Web.Mvc
@using FluxDigital.Feature.Search.Models
@using PagedList.Mvc
@using Sitecore.Configuration
@model BlogPostSearchResultsModel
<div class="wrapper">
<form class="search" action="" method="GET">
<div class="search-box">
@fluxdigital
fluxdigital / BlogPostSearchResultsController.cs
Last active September 16, 2022 00:01
Blog Post Search Results Controller
public class BlogPostSearchResultsController : SitecoreController
{
private readonly ISearchService _blogPostSearchService;
public BlogPostSearchResultsController(ISearchService BlogPostSearchService)
{
_blogPostSearchService = BlogPostSearchService;
}
public ActionResult Results()
@fluxdigital
fluxdigital / BlogPostSearchIndexJob.cs
Last active September 15, 2022 23:34
SiteCron Job to index blog posts
public class BlogPostSearchIndexJob : IJob
{
private readonly ISearchService _blogPostSearchService;
private readonly ILogService _logService;
public BlogPostSearchIndexJob() :
this(ServiceLocator.ServiceProvider.GetService<ISearchService>(),
ServiceLocator.ServiceProvider.GetService<ILogService>(),
{
public BlogPostSearchResultsModel GetResults(BlogPostSearchResultsModel blogPostSearchResultsModel, string searchTerm, int resultsPerPage, int currentPage)
{
using (new SecurityDisabler())
{
try
{
var solrCharsToAllow = "()-+*./' ";
var solrCharsToEscape = "(,),||,!,[,],^,~,?,:,-,+,\""; //split on comma
var safeSearchTerm = searchTerm.Trim().RemoveSpecialCharacters(solrCharsToAllow);
@fluxdigital
fluxdigital / Index-Content.ps1
Last active September 14, 2022 16:22
Adds the items to the custom index
public int IndexContent()
{
var indexedCount = 0;
using (new SecurityDisabler())
{
try
{
//get the blog posts from Sitecore
var blogPostsRootPath = _master.GetItem(Settings.GetSetting("BlogPostsRootPath"));
<#
Function used to find the CM Url
#>
function Get-CmUrl($item){
$site = [Sitecore.Sites.SiteContext]::GetSite("website")
New-UsingBlock(New-Object -TypeName "Sitecore.Sites.SiteContextSwitcher" -ArgumentList $site) {
$urlOptions = [Sitecore.Links.LinkManager]::GetDefaultUrlOptions()
$urlOptions.AlwaysIncludeServerUrl = $True
<#
Function used to move preview site to the top of the list
#>
function Move-Preview-Site-To-Top($newSiteId){
$sxaSitesList = Get-Item -Path "master:/sitecore/system/Settings/Foundation/Experience Accelerator/Multisite/Management/Sites"
$orderValuesCurrent = $sxaSitesList.Fields["Order"].Value;
write-host "New Site ID: $($newSiteId)"
write-host "Current Order Values: $($orderValuesCurrent)"
<#
### Removes all existing SXA 'Draft' Sites ###
.Description
Finds all SXA Draft sites and deletes them.
#>
$sxaSites = Get-ChildItem -Path "/sitecore/content/Sites"
$successCount = 0
$failCount = 0
$siteGroupingPath = "Settings/Site Grouping"
<#
### Displays a 'Draft Site' message in Experience Editor ###
.Description
The $text variable below should be edited as required.
#>
$title = "Displaying Draft Site"
$text = "You are viewing the draft (Master DB) version of the site."
$icon = @{$true="Office/32x32/information.png";$false="Applications/16x16/warning.png"}[$SitecoreVersion.Major -gt 7]