Synthesis Solr Support Now Available (Beta)

Solr Support is Finally Here!

History

Three years ago, Jeff Darchuk set out with a mission: Add Solr Support to Synthesis. It was nearly finished, but the pull request never made it in. It’s been a requested feature for quite some time, and I’m happy to announce it’s finally here!

What’s the Deal?

I’m releasing support for Solr in Synthesis 8.2.7. It’s up on NuGet as a new package: Synthesis.Solr. I am planning on leaving it in beta for about a month.

Upgrading

There are a few things to note in this release of Synthesis:

Sitecore Version Update

Synthesis 8.2.7 only supports Sitecore 8.2 and higher. Synthesis search support is now using Sitecore DI, which is only available starting on 8.2.

Config Changes/Additions

There are two config files you need to pay attention to if you are upgrading.

Synthesis.config

The section was added to this file in order to register the new IQueryableResolvers. Paste this into your config file:

<services>
    <!-- SEARCH CONTEXT RESOLVER Synthesis will use this pipeline to resolve the search queryable for the current search index. -->
    <register serviceType="Synthesis.ContentSearch.IQueryableResolver, Synthesis" implementationType="Synthesis.ContentSearch.Lucene.ResolveLuceneQueryable, Synthesis" lifetime="Singleton" />
</services>

For reference, see these lines in Github.

Synthesis.Solr.config

There’s nothing you need to do here. This file comes standard with the Synthesis.Solr package. I’m only calling it out to bring attention to it if your solution has config files in non-standard locations.

How do I use it?

It’s actually no different from Lucene in terms of usage. There’s a good example on the README of the Synthesis repo. Here’s a more condensed example, though:

public IList<IPageItem> SearchPages(string keyword)
{
    using (var context = ContentSearchManager.CreateSearchContext(new SitecoreIndexableItem(Sitecore.Context.Item)))
    {
    // Create the main "And" predicate for filtering everything
    var filter = PredicateBuilder.True<IPageItem>();
    filter = filter.And(f => f.Language == Context.Language);
    filter = filter.And(f => f.IsLatestVersion);
    filter = filter.And(f => f.TemplateIds.Contains(Page.ItemTemplateId));
    filter = filter.And(f => f.AncestorIds.Contains(ItemIDs.ContentRoot));
     
    // Create an "Or" predicate for searching text
    var searchQuery = PredicateBuilder.False<IPageItem>();
    searchQuery = searchQuery.Or(q => q.SearchableContent.Like(keyword, 1F));
    searchQuery = searchQuery.Or(q => q.MetaKeywords.RawValue.Like(keyword, 1F).Boost(1.3F));
    searchQuery = searchQuery.Or(q => q.PageTitle.RawValue.Like(keyword, 1F).Boost(1.4F));
     
    // Add the text predicate back to the main filter
    filter = filter.And(searchQuery);
     
    // Return a list of IPageItem's matching the above filter
    return context.GetSynthesisQueryable<IPageItem>().Where(filter).ToList();
    }
}