Skip to content

Instantly share code, notes, and snippets.

@benmccallum
Forked from patrickperrone/ChangeSearchProvider.ps1
Last active February 15, 2016 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmccallum/33a248b2c6efcefaf29c to your computer and use it in GitHub Desktop.
Save benmccallum/33a248b2c6efcefaf29c to your computer and use it in GitHub Desktop.
This PowerShell script will change your Sitecore instance search provider from Lucene to Solr or vice versa. It can be called from a build process to do so.
Function Set-SCSearchProvider
{
param([string]$choice, [string]$rootPath)
$validInput = $true;
#test that path is valid
If (!(Test-Path -Path $rootPath))
{
Write-Host "The supplied path was invalid or inaccessible." -ForegroundColor Red;
$validInput = $false;
}
#test that choice is valid
ElseIf (($choice -ne "L") -and ($choice -ne "S"))
{
Write-Host "You must choose L or S." -ForegroundColor Red;
$validInput = $false;
}
If ($validInput)
{
If (($choice -eq "L"))
{
Write-Host "Set to Lucene." -ForegroundColor Yellow;
$selectedProvider = "Lucene";
$deselectedProvider = "Solr";
}
ElseIf (($choice -eq "S"))
{
Write-Host "Set to Solr." -ForegroundColor Yellow;
$selectedProvider = "Solr";
$deselectedProvider = "Lucene";
}
#enumerate all config files to be enabled
$filter = "*" + $selectedProvider + "*.config*";
$selectedProviderFiles = Get-ChildItem -Recurse -File -Path $rootPath -Filter $filter;
foreach ($file in $selectedProviderFiles)
{
Write-Host $file.Name;
if (($file.Extension -ne ".config"))
{
$newDestination = [io.path]::GetDirectoryName($file.FullName) + "\" + [io.path]::GetFileNameWithoutExtension($file.FullName);
$newFile = Move-Item -Path $file.FullName -Destination $newDestination -Force -PassThru;
Write-Host "-> " $newFile.Name -ForegroundColor Green;
}
}
#enumerate all config files to be disabled
$filter = "*" + $deselectedProvider + "*.config*";
$deselectedProviderFiles = Get-ChildItem -Recurse -File -Path $rootPath -Filter $filter;
foreach ($file in $deselectedProviderFiles)
{
Write-Host $file.Name;
if ($file.Extension -eq ".config")
{
$newDestination = [io.path]::GetDirectoryName($file.FullName) + "\" + $file.Name + ".disabled";
$newFile = Move-Item -Path $file.FullName -Destination $newDestination -Force -PassThru;
Write-Host "-> " $newFile.Name -ForegroundColor Green;
}
}
}
}
Set-SCSearchProvider $args[0] $args[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment