ASP.NET, Enterprise Search

The complete guide to getting started with Solr in Sitecore

Solr is a highly reliable search platform that powers the search and navigation features of many of the world’s largest internet sites. It provides distributed indexing, replication with load-balanced querying, automated failover and recovery, centralized configuration and more.

Sitecore on the other hand, is a leading digital experience software used by organizations globally to create seamless, personalized digital experiences. Sitecore is a web content and experience management platform that includes standard CMS, commerce and digital marketing tools in an integrated environment that runs on .NET and the Microsoft web stack (Windows, IIS, SQL Server, etc.)

When we combine Sitecore’s power with Solr search capabilities we get the best of both worlds. Using Solr with Sitecore requires a few installation and configuration steps. In some cases, these steps can be automated using tools like SIF (the Sitecore Installation Framework) while in others they must be manually implemented. The following steps demonstrate how you can install and configure Solr for use with Sitecore:

Solr installation

The first step to using Solr with Sitecore is installing it. These instructions are for setting Solr up as a Windows service on a single machine for use alongside Sitecore 9.1. This is typically the configuration used by developers for development purposes or for basic situations like a demo server. Different configurations and different versions of Sitecore may require different Solr topologies and different setup steps. You will want to perform these steps prior to installing Sitecore itself as the installation scripts provided by Sitecore expect Solr to be running before they are run.

Solr logging

Solr logs are a key way to know what’s happening in the system. By default, Solr log messages will be written to server/logs/solr.log. If problems arise, the Solr logs help understand the causes and are invaluable for troubleshooting. The Solr Admin web interface has a section for logging which allow you to set the log level for many different categories of logging. If individual categories don’t have their own logging level, then they will inherit the logging level of their parent. This makes it easy to adjust and maintain logging levels by setting the logging level of a common parent.

Indexing Sitecore content in Solr

First, let’s understand how indexing works and ensure that Sitecore data is appearing in our index.

1. First ensure the Connection String for Solr is correct in your connection strings config (typically “connectionstrings.config”).

2. Then create a Data Template in Sitecore

3. Create a View Rendering to display the content that will be indexed using your standard Sitecore development methods.


4. Use the template you created to create a few content items and add some data.

5. Next make sure the content is indexed by using the Sitecore Control Panel’s Index manager. If you are using any existing indexes, then rebuild it.


6. After indexing, check that the data is present in the index. This is done by going into the Solr interface (at https://localhost:8986/solr). Choose the core representing the Sitecore database you want to view content in from the dropdown, then enter the parameters seen below.

You should now see your content in the Solr index.

Creating a basic Sitecore search page with Solr

1. After indexing is done, Open a new solution in Visual Studio.
2. Create a Custom Route for Sitecore URL under App_Start folder.

Create a custom processor for the initialize pipeline and define custom route in the Process method like the following code:

Add this processor to the initialize pipeline right before the Sitecore InitializeRoutes processor. You can do this with the help of the configuration patch file in the following way:

Config File Code:

3. Create the Sitecore Search View

Create a Search text box and button on the HTML page where the user will be able to type and search for the record from Solr. Write script to create the AJAX call to call server-side controller action method on click of Search button created in above step. Below is the full code for HTML and script.

4. Implement the Controller Code

Here, we are creating a “DoSearch” method for the search results while “GetSearchPredicate” method for appending the predicate for the search query and we are returning the JSON value.

5. Implement The Model Code

Solr creates the property on the Solr server for all the default and custom fields. To use those fields in code, map them in a Class given below:

6. See your results

Now that all the parts are all in place it’s time to see the fruits of our labor.

First build and publish whole solution. Then perform a search. If you get search results, everything is working.

About The Author