Dieses Blog durchsuchen

Montag, 5. Oktober 2015

Sitecore search: How to use Spell correction / suggestion in Sitecore with Lucene.NET

Recently our client asks us to extend the search feature with a spell check and provide suggestions. After some search I found some code that help me to bring the feature live. Thanks to tanasuk.

See the small method code here:

 public static String[] GetSpellCorrectionSuggestions(string searchTerm, int numberOfSuggestions = 5)

            string[] suggestions = null;

            if (string.IsNullOrEmpty(searchTerm))

                return null;

                string indexPath = string.Format("{0}\\{1}\\", Sitecore.Configuration.Settings.IndexFolder, ConfigurationHelper.GetIndexName());
                Lucene.Net.Index.IndexReader reader = Lucene.Net.Index.IndexReader.Open(

                    FSDirectory.Open(indexPath), false);

                SpellChecker.Net.Search.Spell.SpellChecker speller =
                    new SpellChecker.Net.Search.Spell.SpellChecker(new RAMDirectory());

                speller.IndexDictionary(new LuceneDictionary(reader, "_title"));
                suggestions = speller.SuggestSimilar(searchTerm, numberOfSuggestions);
                return suggestions;
            catch (Exception ex)
                Sitecore.Diagnostics.Log.Error(ex.Message, ex, Sitecore.Context.Item);
                return suggestions;

Freitag, 2. Oktober 2015

sitecore [branch no longer exists]


[branch no longer exists] - 


If items were created from template, 'MasterId' field has '00000000-0000-0000-0000-000000000000' value. MasterId field in SQL database is responsible for 'created from'. Update MasterId field to 00000000-0000-0000-0000-000000000000.

How to SQL command:

Do a backup. 
Be careful, use your own query and use filter.
update [your_db_name_master].[dbo].[Items] set MasterID = '00000000-0000-0000-0000-000000000000' where TemplateID = '<your TemplateID>'