Skip to content

Ehab ElGindy

sitecore blog

  • About
Home > Page 2
Published June 28, 2014 by ehabelgindy

Sitecore 7 & Solr – Search Context Extension Methods to Implement “Did you mean …?” Spellcheck

Share Button

One great way to improve the search experience on a website is to suggest alternate/corrected queries if the original ones were misspelled, similar to the “Did you mean …” provided by Google. If you are interested to implement this feature, I’ve some good news and some bad news for you. The good news is, this feature can be effortlessly implmeneted using the Solr Spellcheck search component. The bad news is, unfortunately the Spellcheck search component is not supported yet by the Sitecore 7/Solr search provider.

This article will show you an easy way to extend the search provider – using extension methods – to implement the Spellcheck feature. Two main steps are needed here; configure Solr to enable the Spellcheck component, and write the extension methods.

1. Enabling the Spellchecker in Solr

Edit your solrconfig.xml and locate the following element:

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">

Under the searchComponent element, configure the field that will be used for building the suggested search queries. It should look like:

<str name="field">title_t</str>

Read More Sitecore 7 & Solr – Search Context Extension Methods to Implement “Did you mean …?” Spellcheck

Sitecore Solr

Search Sitecore Solr Spellcheck

Published June 4, 2014 by ehabelgindy

Sitecore 7 & Solr – Sorting Search Results by Score

Share Button

The Solr search provider in Sitecore 7 allows users to rank the search results using different types of boosting methods. This article shows how to use the Query-Time Boosting to sort the search results and highlights the common mistakes that developers should avoid.

Assume that you want to run a search query over a set of Sitecore items, each of which has a title and description fields, and you would like the score of the results that contain the search keyword in the title to be higher than the ones contain the search keyword in the description.

The search query that uses Query-Time Boosting should look like:

var query = "guitar";
var dataQuery = context.GetQueryable<SearchResultItem>()
.Where(i => i.Title == query.Boost(3.0f) || i.Description == query.Boost(1.0f))

 

Read More Sitecore 7 & Solr – Sorting Search Results by Score

Sitecore Solr

Search Sitecore Solr

Published May 1, 2014 by ehabelgindy

Sitecore 7 & Solr search auto-complete using NGram

Share Button

If you are about to implement an auto-compelte text box for your search page, then you are in the right place. This article will show you how to display search suggestions using Sitecore 7 and Solr Search Provider. Solr is a very powerful search platform which provides many indexing and query time analyzers. The NGram analyzer is used here to implement search auto-complete feature. Before I go through the details, please don’t do the following:

Don’t use String.Contains()

var context = index.CreateSearchContext();
var results = context.GetQueryable().Where(i=> i.Title.Contains(searchText));
...

Please don’t ever do this, your client will come back complaining that, when their customers search for “pen” they get irrelevant suggestions such as “Dispenser”, “Open” and “Sharpener”.

Don’t use String.StartsWith()

var context = index.CreateSearchContext();
var results = context.GetQueryable().Where(i=> i.Title.StartsWith(searchText));
...

This won’t work as well because it will fail to return results such as “blue pen” where the title doesn’t start with the word “pen”.

The proper way (Using NGram)

These are the steps to properly implement this feature:
Read More Sitecore 7 & Solr search auto-complete using NGram

Sitecore Solr

Search Sitecore Solr

« Previous 1 2

Recent Posts

  • From Hours to Seconds – The Awesome Performance of Sitecore Publishing Service V2
  • Run Sitecore Publishing as Azure Cloud Service
  • How to Achieve Zero-Downtime Sitecore Deployments (EF Automatic Migrations) – Part III
  • How to Achieve Zero-Downtime Sitecore Deployments (Solr Search) – Part II
  • How to Achieve Zero-Downtime Sitecore Deployments (Architecture) – Part I

Recent Comments

  • Akshansh on Sitecore 7 & Solr – Why SearchResultItem.Url is always null?
  • ehabelgindy on Sitecore Spatial Search using Solr
  • James on Sitecore Spatial Search using Solr
  • James on Sitecore Spatial Search using Solr
  • James on Sitecore Spatial Search using Solr

Archives

  • February 2017
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • August 2014
  • June 2014
  • May 2014

Categories

  • Entity Framework
  • publishing
  • Scalability
  • Session State
  • Sitecore
  • Solr

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Ehab ElGindy

sitecore blog
Free WordPress Blog Theme by Compete Themes.