Sitefinity is an enterprise level content management system and many of our clients have chosen to go with it at our recommendation. As thrilled as these clients are with all the great features of Sitefinity, many of them have expressed their dissatisfaction with Sitefinity’s search feature. When you visit an association’s website and you want to search for an article you remember reading, you expect that the result of your query will contain the article that you were searching for. Google has set the bar high for us.
Unfortunately, Sitefinity’s search simply does not work that well. When you have customized a website with members only pages and a large number of custom content types, it does not seem to index correctly or display the results properly. We know Sitefinity uses Lucene on the backend somehow, but until Telerik makes some improvements, here at NonprofitCMS our engineers have had to find a number of workarounds.
Our first attempt involved combining Sitefinity’s search results with Google’s Custom Search. This worked okay for some clients, but there were some additional limitations that Google Custom Search places on you with regards to the number of search results you can obtain, and the number of queries you can make per day. Additionally, it was unhelpful with regards to members only pages.
We decided now to work with Solr. Solr is a search engine built on top of Lucene and is excellent. The challenge is that we would not want to be rolling out our own Solr server, fortunately for us Amazon EC2 has a dedicated Solr Image we could deploy in a worry free manner. All we need to care about is pushing documents and searching on documents. Super simple.
Let’s dig into some code on how we did this.
First step is to index all the web pages and custom content types that our client has on their website. We put in a support ticket to Telerik to find out how we can pull the content down from all our front end web pages. After some hacks, we managed to get it done.
We also needed to grab all of our dynamic, custom content type submissions from our client and added that to the list of search items we would add to our Solr search engine. And finally, we needed to connect to our WebSolr service. We used the SolrNet library to help out with this.
try
{
Startup.Init<AggregateSearchItem>(“http://index.websolr.com/solr/YOURKEYHERE”);
}
catch { }
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<AggregateSearchItem>>();
and … to finish indexing…
foreach (var i in searchItems)
{
solr.Add(i);
}
solr.Commit();
It only took about a minute to run through and send about 1000 documents to our WebSolr service.
And finally, to search on items…
No rocket science there. Make the call with your search query and get the results.
Notes:
We had some difficulties with Solr’s schema.xml. The default schema that comes with Solr did not work properly and so we took one of their pre-made schemas and modified it to suit our needs.
That’s how we integrated Solr with Sitefinity.
Thanks.