Share Button

A simple architecture was proposed in Part I of this article to avoid down times during the Sitecore content and code deployments. In this article, the deployments problems related to search is discussed and a potential solution is illustrated.

What search technology to use?

A straight forward answer is .. NOT Lucene. Although it’s the default search provider for Sitecore, it doesn’t do well within a multi-instances environment as the instances of the index will often go out-of-sync. Other search providers can be use such as SolrCoveo for Sitecore and Elastic search. Each of these technologies may require different setup/configuration to achieve the goal of this article.

The rest of this article is based on Solr – as it’s currently the alternate search technology provided by Sitecore – showing what the potential problems are and how to avoid these problems.

 

What part of the search can cause downtime during deployments?

Two things can go wrong here:

1. Solr configuration updates

If you implemented a new feature in your website that requires a Solr configuration updates (e.g. auto complete using NGram or “Did you mean …” spellchecking) then you have to be very careful about they way of pushing the schema/config updates to the Solr server.

One mistake that developers do is restarting the Solr server to force it to read the new updates. Once the service is restarted, Sitecore will immediately show the yellow screen of death and the site will go down till the Solr server is up and running again.

Thankfully, Solr has a very helpful feature – Reload – that allows loading the config updates without causing downtime. Here is a quote from the Solr wiki pages describing the Reload function

Load a new core from the same configuration as an existing registered core. While the “new” core is initalizing, the “old” one will continue to accept requests. Once it has finished, all new request will go to the “new” core, and the “old” core will be unloaded.

  • http://localhost:8983/solr/admin/cores?action=RELOAD&core=core0

This can be useful when (backwards compatible) changes have been made to your solrconfig.xml or schema.xml files (e.g. new <field> declarations, changed default params for a <requestHandler>, etc…) and you want to start using them without stopping and restarting your whole Servlet Container.

You can also reload a Solr core using the admin portal by going to “Core Admin” -> Click on the core you want to reload -> Click the Reload button as shown in the following screenshot:

Solr Core Reload
Solr Core Reload

Read More How to Achieve Zero-Downtime Sitecore Deployments (Solr Search) – Part II

Scalability Session State Sitecore Solr

Share Button

Here is the source code of the awesome cars demo site I presented at the Sitecore User Group (Cardiff) on 24/11/2014. This site illustrates how to use Sitecore and Solr…

Read More Awesome Cars Demo Site

Sitecore Solr

Share Button

One essential thing that you will need to do in almost every search implementation is linking each search result item to their full (details) pages. The Sitecore content search provider for Solr doesn’t index the item url by default, here are the steps you need to get it working:

The Sitecore.ContentSearch.SearchTypes.SearchResultsItem base class contains the following property:

[IndexField("urllink")]
public virtual string Url {get; set;}

Consider the following sample code to get the urls of items located under a specific parent:

...
using(var context = index.CreateSearchContext())
{
  var query = context.GetQueryable<SearchResultItem>();
  var pageUrls = query.Where(i => i.Parent == new ID("<ParentItemIdHere>"))
                      .GetResults().Hits.Select(h => h.Document.Url).ToList();
}

Read More Sitecore 7 & Solr – Why SearchResultItem.Url is always null?

Sitecore Solr

Share Button

The Solr search provider in Sitecore 7 works quite well if the search query contains a single term. However, if the search query contains multiple terms, you will need to tweak your code a little bit to get the expected results.

The following codes performs a search using a query that contains a single term.

 var indexName = "sitecore_web_index";
 var index = ContentSearchManager.GetIndex(indexName);
 using (var context = index.CreateSearchContext())
 {
 var query = "paint";
 var dataQuery = context.GetQueryable()
 .Where(i => i.Title == query);
 var results = dataQuery.GetResults().Hits.Select(h => h.Document);
 }

The Sitecore search provider generates the following Solr query:

title_t:(paint)

However, if you replace the

var query = "paint";

With

var query = "purple paint";

The generated Solr query will be:

title_t:("purple paint")

If the search query contains whitespace characters, the search provider will automatically wrap the query terms in double quotes. This will cause Solr to skip the query analysers – such as tokenization and stemming. So, it will only return results containing the string “purple paint” in the title, and will fail to match titles such as “purple-paint”, or “purple and red paint” and so on.

In order to work around the whitespace problem, you can implement one of the following solutions:

Read More Sitecore 7 & Solr – Multi term search

Sitecore Solr