Skip to content

Instantly share code, notes, and snippets.

@NaibafCH
Last active December 19, 2016 11:46
Show Gist options
  • Save NaibafCH/efd9e5599d938fa991fd5710678cc68e to your computer and use it in GitHub Desktop.
Save NaibafCH/efd9e5599d938fa991fd5710678cc68e to your computer and use it in GitHub Desktop.
using System.IO;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.NGram;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Util;
using Sitecore.Configuration;
namespace Sitecore.ContentSearch.LuceneProvider.Analyzers
{
public class EdgeNgramAnalyzer : Lucene.Net.Analysis.Analyzer
{
public override TokenStream TokenStream(string fieldName, TextReader reader)
{
var defaultAnalyzer = new LowerCaseFilter(new StandardTokenizer(Version.LUCENE_30, reader)) as TokenStream;
var minLength = Settings.GetIntSetting("Sitecore.ContentSearch.Ngrams.MinLength", 3);
var maxLength = Settings.GetIntSetting("Sitecore.ContentSearch.Ngrams.MaxLength", 20);
var ngramsFront = new EdgeNGramTokenFilter(defaultAnalyzer, Side.FRONT, minLength, maxLength);
return new EdgeNGramTokenFilter(ngramsFront, Side.BACK, minLength, maxLength);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment