This blog will help you rebuild the Solr index using the PowerShell script more efficiently.
The following code snippet will help to reindex a specific item instead of rebuilding the whole index programmatically using the PowerShell script.
This code should work with any version of Sitecore.
Open - Development Tools -> PowerShell ISE and paste the following code.
Modify the paths and fields according to your template fields, if required.
Reindex specific data items for the particular index
PowerShell script code:
[Sitecore.ContentSearch.ContentSearchManager]::Indexes | Foreach-Object { $options.Add($_.Name, $_.Name) }
$props = @{
Parameters = @(
@{Name="indexName"; Title="Choose an index"; Options=$options; Tooltip="Choose Index"}
)
Title = "Index Wizard"
Description = "Select an index."
Width = 300
Height = 300
ShowHints = $true
}
$result = Read-Variable @props
if ($result -eq "ok") {
$index = [Sitecore.ContentSearch.ContentSearchManager]::GetIndex($indexName)
}
Close-Window
Get-ChildItem -path "/sitecore/content/Home/" -language en-Us -Recurse | Where-Object { $_.TemplateName -eq 'Article' } | ForEach-Object {
if([string]::IsNullOrEmpty($_."Any Field")){
write-host $_.Name "SKIPPED"
}
else{
write-host $_.Name $_.Paths.FullPath
[Sitecore.ContentSearch.Maintenance.IndexCustodian]::Refresh($index, [Sitecore.ContentSearch.SitecoreIndexableItem]$_)
}
}