In this topic, I will describe how I created a Sitecore’s control panel tool for Administrators and developers who want to check the Solr Administration User Interface directly.
Sometimes Administrators do not find easily the Solr service address that the Sitecore instance is using. This module will add a new section in the Control Panel, called “Solr Search”, that will have the option to access Solr Admin UI.
First, we will add a custom icon for the utility so we should have a Solr logo image with different sizes: 16×16, 24×24 and 32×32 (you could also have 48×48 and 128×128). It’s recommended that the image should have a transparent background unless you want the icon to be a square. Zip all these images with structure with the same name as the containing folder (Solr.zip):
- Solr
- 16×16
- solr.png
- 24×24
- solr.png
- 32×32
- solr.png
- 16×16
Upload this file to /sitecore/shell/Themes/Standard/ and now you custom icons will be available. If you want this icon download it from here.
Let’s begin with the Control Panel section. To add your own tool, you need to add a new category under /sitecore/content/Applications/Control Panel, using the template “Task Page”. you can easily duplicate an existent one. In this particular case, we will create a new item called Solr Search and we must set a Header and an Icon. Go to this section if you want to know how to add a custom icon.
Under the new item that we created, we need to create a new “Task option” item and we will call it “Administration Panel”. The Click field is the Sitecore command to execute when this tool is clicked.
The new command “indexing:solradminpanel” should be defined either in the App_Config/Commands.config file or in a custom configuration file (in our case we will use a new config file to set this command).
<?xml version="1.0" encoding="utf-8" ?> <configuration> <sitecore> <commands> <command name="indexing:solradminpanel" type="SharedSource.Solr.Commands.AdminPanel,SharedSource.Solr"/> </commands> </sitecore> </configuration>
As you may notice, in the type attribute we should put the full command name and the assembly name separated by a comma.
Now, we have to create the command which is a class that must inherit from Sitecore.Shell.Framework.Commands.Command and override the Execute method.
See the code below for reference.
using System; using Sitecore.Configuration; using Sitecore.Globalization; using Sitecore.Shell.Framework.Commands; using Sitecore.Text; using Sitecore.Web.UI.Sheer; namespace SharedSource.Solr.Commands { [Serializable] public class AdminPanel : Command { public AdminPanel() { } /// <summary> /// Executes the command in the specified context. /// </summary> /// <param name="context">The context.</param> public override void Execute(CommandContext context) { //Check if Solr is enabled string contentSearch = Settings.GetSetting("ContentSearch.Provider"); if (string.IsNullOrWhiteSpace(contentSearch) || !contentSearch.Equals("solr", StringComparison.InvariantCultureIgnoreCase)) { string message = Translate.Text("Solr is not enabled!"); SheerResponse.Alert(message); return; } //Get Solr string serviceBaseAddress = Settings.GetSetting("ContentSearch.Solr.ServiceBaseAddress"); if (string.IsNullOrWhiteSpace(serviceBaseAddress)) { string message = Translate.Text("Service Base Address is not defined!"); SheerResponse.Alert(message); return; } //Open Solr Administration UI UrlString webSiteUrl = new UrlString(serviceBaseAddress); SheerResponse.Eval("window.open('" + webSiteUrl + "', '_blank')"); } } }
I’ve defined two new dictionary entries for the Alert messages:
- “Solr is not enabled”: when Solr is disabled, it means that the current Index Provider is Lucene or Coveo.
- “Service Base Address is not defined”: when the setting “ContentSearch.Solr.ServiceBaseAddress” is not defined. The default value of this setting is: “http://localhost:8983/solr“
Finally, when the user hits the link, the module will open the Solr Administration User Interface where administrators or developers can what how Sitecore items are being indexed and also perform their own queries for testing purposes.
If you want the resources of this module, please refer to this link
That’s all folks. Happy Sitecoring 😉