Skip to content

Instantly share code, notes, and snippets.

@christofur
Created June 13, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christofur/e2ea406c21bccd3b032c9b861df0749b to your computer and use it in GitHub Desktop.
Save christofur/e2ea406c21bccd3b032c9b861df0749b to your computer and use it in GitHub Desktop.
Viewing Sitecore search analyzer output
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Fr;
using Lucene.Net.Analysis.Tokenattributes;
using Sitecore.ContentSearch.LuceneProvider.Analyzers;
using System;
using System.IO;
namespace SitecoreAnalyzers
{
class Program
{
static void Main(string[] args)
{
var text = "Did the Quick Brown Fox jump over the Lazy Dog?";
var text_fr = "Le Fox brune rapide a-t-il sauté sur le chien paresseux?";
Console.WriteLine("** CaseSensitiveStandardAnalyzer **");
displayTokens(new CaseSensitiveStandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), text);
Console.WriteLine("** LowerCaseKeywordAnalyzer **");
displayTokens(new LowerCaseKeywordAnalyzer(), text);
Console.WriteLine("** NGramAnalyzer **");
displayTokens(new NGramAnalyzer(), text);
Console.WriteLine("** StandardAnalyzerWithStemming **");
displayTokens(new StandardAnalyzerWithStemming(Lucene.Net.Util.Version.LUCENE_30), text);
Console.WriteLine("** SynonymAnalyzer - see http://firebreaksice.com/sitecore-synonym-search-with-lucene/ **");
displayTokens(new SynonymAnalyzer(new XmlSynonymEngine("synonyms.xml")), text);
Console.WriteLine("** FrenchAnalyzer **");
displayTokens(new FrenchAnalyzer(Lucene.Net.Util.Version.LUCENE_30), text_fr);
Console.ReadKey();
}
private static void displayTokens(Analyzer analyzer, string text)
{
var stream = analyzer.TokenStream("content", new StringReader(text));
var term = stream.AddAttribute<ITermAttribute>();
while (stream.IncrementToken())
{
Console.Write("'" + term.Term + "', ");
}
Console.Write("\n\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment