|
| 1 | +using Nest.Tests.Unit.Core.Indices.Analysis.Tokenizers; |
| 2 | +using NUnit.Framework; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Reflection; |
| 7 | +using System.Text; |
| 8 | + |
| 9 | +namespace Nest.Tests.Unit.Core.Indices.Analysis.Analyzers |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class AnalyzerTests : BaseAnalysisTests |
| 13 | + { |
| 14 | + [Test] |
| 15 | + public void CustomAnalyzerTest() |
| 16 | + { |
| 17 | + var result = this.Analysis(a => a |
| 18 | + .Analyzers(aa => aa.Add("myCustom", new CustomAnalyzer |
| 19 | + { |
| 20 | + Tokenizer = "myTokenizer", |
| 21 | + Filter = new string[] { "myTokenFilter1", "myTokenFilter2" }, |
| 22 | + CharFilter = new string[] { "my_html" }, |
| 23 | + Alias = new string[] { "alias1", "alias2" } |
| 24 | + }) |
| 25 | + ) |
| 26 | + ); |
| 27 | + |
| 28 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 29 | + } |
| 30 | + |
| 31 | + [Test] |
| 32 | + public void KeywordAnalyzerTest() |
| 33 | + { |
| 34 | + var result = this.Analysis(a => a |
| 35 | + .Analyzers(aa => aa.Add("keyword", new KeywordAnalyzer()))); |
| 36 | + |
| 37 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 38 | + } |
| 39 | + |
| 40 | + [Test] |
| 41 | + public void LanguageAnalyzerTest() |
| 42 | + { |
| 43 | + var result = this.Analysis(a => a |
| 44 | + .Analyzers(aa => aa.Add("arabic", new LanguageAnalyzer(Language.Arabic) |
| 45 | + { |
| 46 | + StopWords = new string[] { "foo" }, |
| 47 | + StemExclusionList = new string[] { "bar" }, |
| 48 | + StopwordsPath = "/path/to/stopwords" |
| 49 | + }))); |
| 50 | + |
| 51 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 52 | + } |
| 53 | + |
| 54 | + [Test] |
| 55 | + public void PatternAnalyzerTest() |
| 56 | + { |
| 57 | + var result = this.Analysis(a => a |
| 58 | + .Analyzers(aa => aa.Add("whitespace", new PatternAnalyzer |
| 59 | + { |
| 60 | + Pattern = "\\\\s+", |
| 61 | + Lowercase = false, |
| 62 | + Flags = "g" |
| 63 | + }))); |
| 64 | + |
| 65 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 66 | + } |
| 67 | + |
| 68 | + [Test] |
| 69 | + public void SimpleAnalyzerTest() |
| 70 | + { |
| 71 | + var result = this.Analysis(a => a |
| 72 | + .Analyzers(aa => aa.Add("simple", new SimpleAnalyzer()))); |
| 73 | + |
| 74 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 75 | + } |
| 76 | + |
| 77 | + [Test] |
| 78 | + public void SnowballAnalyzerTest() |
| 79 | + { |
| 80 | + var result = this.Analysis(a => a |
| 81 | + .Analyzers(aa => aa.Add("snowball", new SnowballAnalyzer |
| 82 | + { |
| 83 | + Language = "English", |
| 84 | + StopWords = "these,are,some,stopwords" |
| 85 | + }))); |
| 86 | + |
| 87 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 88 | + } |
| 89 | + |
| 90 | + [Test] |
| 91 | + public void StandardAnalyzerTest() |
| 92 | + { |
| 93 | + var result = this.Analysis(a => a |
| 94 | + .Analyzers(aa => aa.Add("standard", new StandardAnalyzer()))); |
| 95 | + |
| 96 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 97 | + } |
| 98 | + |
| 99 | + [Test] |
| 100 | + public void StopAnalyzerTest() |
| 101 | + { |
| 102 | + var result = this.Analysis(a => a |
| 103 | + .Analyzers(aa => aa.Add("stop", new StopAnalyzer |
| 104 | + { |
| 105 | + StopWords = new string[] { "these","are","some","stopwords"}, |
| 106 | + StopwordsPath = "/path/to/stopwords" |
| 107 | + }))); |
| 108 | + |
| 109 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 110 | + } |
| 111 | + |
| 112 | + [Test] |
| 113 | + public void WhitespaceAnalyzerTest() |
| 114 | + { |
| 115 | + var result = this.Analysis(a => a |
| 116 | + .Analyzers(aa => aa.Add("whitespace", new WhitespaceAnalyzer()))); |
| 117 | + |
| 118 | + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments