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:

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:


However, if you replace the

var query = "paint";


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