From 83b7f5942497889e3cae88002b1c54309a648e2c Mon Sep 17 00:00:00 2001 From: gmarz Date: Wed, 18 Jun 2014 16:31:27 -0400 Subject: [PATCH 1/2] Added Alias collection to CustomAnalyzer --- src/Nest/Domain/Analysis/Analyzers/CustomAnalyzer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Nest/Domain/Analysis/Analyzers/CustomAnalyzer.cs b/src/Nest/Domain/Analysis/Analyzers/CustomAnalyzer.cs index 57782e0c7e0..a032d81ce73 100644 --- a/src/Nest/Domain/Analysis/Analyzers/CustomAnalyzer.cs +++ b/src/Nest/Domain/Analysis/Analyzers/CustomAnalyzer.cs @@ -25,5 +25,8 @@ public CustomAnalyzer() : this("custom") {} [JsonProperty("char_filter")] public IList CharFilter { get; set; } + + [JsonProperty("alias")] + public IList Alias { get; set; } } } \ No newline at end of file From f5486986d11c97926e3a8e0fb182f47534b632ce Mon Sep 17 00:00:00 2001 From: gmarz Date: Thu, 19 Jun 2014 10:30:50 -0400 Subject: [PATCH 2/2] Added unit tests for all analyzers --- .../Analysis/Analyzers/AnalyzerTests.cs | 121 ++++++++++++++++++ .../Analyzers/CustomAnalyzerTest.json | 17 +++ .../Analyzers/KeywordAnalyzerTest.json | 13 ++ .../Analyzers/LanguageAnalyzerTest.json | 16 +++ .../Analyzers/PatternAnalyzerTest.json | 16 +++ .../Analyzers/SimpleAnalyzerTest.json | 13 ++ .../Analyzers/SnowballAnalyzerTest.json | 15 +++ .../Analyzers/StandardAnalyzerTest.json | 13 ++ .../Analysis/Analyzers/StopAnalyzerTest.json | 15 +++ .../Analyzers/WhitespaceAnalyzerTest.json | 13 ++ .../Nest.Tests.Unit/Nest.Tests.Unit.csproj | 14 ++ 11 files changed, 266 insertions(+) create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/AnalyzerTests.cs create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/CustomAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/KeywordAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/LanguageAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/PatternAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SimpleAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SnowballAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StandardAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StopAnalyzerTest.json create mode 100644 src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/WhitespaceAnalyzerTest.json diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/AnalyzerTests.cs b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/AnalyzerTests.cs new file mode 100644 index 00000000000..a9e0e1f331d --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/AnalyzerTests.cs @@ -0,0 +1,121 @@ +using Nest.Tests.Unit.Core.Indices.Analysis.Tokenizers; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace Nest.Tests.Unit.Core.Indices.Analysis.Analyzers +{ + [TestFixture] + public class AnalyzerTests : BaseAnalysisTests + { + [Test] + public void CustomAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("myCustom", new CustomAnalyzer + { + Tokenizer = "myTokenizer", + Filter = new string[] { "myTokenFilter1", "myTokenFilter2" }, + CharFilter = new string[] { "my_html" }, + Alias = new string[] { "alias1", "alias2" } + }) + ) + ); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void KeywordAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("keyword", new KeywordAnalyzer()))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void LanguageAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("arabic", new LanguageAnalyzer(Language.Arabic) + { + StopWords = new string[] { "foo" }, + StemExclusionList = new string[] { "bar" }, + StopwordsPath = "/path/to/stopwords" + }))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void PatternAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("whitespace", new PatternAnalyzer + { + Pattern = "\\\\s+", + Lowercase = false, + Flags = "g" + }))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void SimpleAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("simple", new SimpleAnalyzer()))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void SnowballAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("snowball", new SnowballAnalyzer + { + Language = "English", + StopWords = "these,are,some,stopwords" + }))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void StandardAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("standard", new StandardAnalyzer()))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void StopAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("stop", new StopAnalyzer + { + StopWords = new string[] { "these","are","some","stopwords"}, + StopwordsPath = "/path/to/stopwords" + }))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + + [Test] + public void WhitespaceAnalyzerTest() + { + var result = this.Analysis(a => a + .Analyzers(aa => aa.Add("whitespace", new WhitespaceAnalyzer()))); + + this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod()); + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/CustomAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/CustomAnalyzerTest.json new file mode 100644 index 00000000000..bfe772d48b8 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/CustomAnalyzerTest.json @@ -0,0 +1,17 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "myCustom": { + "tokenizer": "myTokenizer", + "filter": [ "myTokenFilter1", "myTokenFilter2" ], + "char_filter": [ "my_html" ], + "alias": [ "alias1", "alias2" ], + "type": "custom" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/KeywordAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/KeywordAnalyzerTest.json new file mode 100644 index 00000000000..63568594ddf --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/KeywordAnalyzerTest.json @@ -0,0 +1,13 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "keyword": { + "type": "keyword" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/LanguageAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/LanguageAnalyzerTest.json new file mode 100644 index 00000000000..b4db1b6b72a --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/LanguageAnalyzerTest.json @@ -0,0 +1,16 @@ + { + "settings": { + "index": { + "analysis": { + "analyzer": { + "arabic": { + "stopwords": ["foo"], + "stem_exclusion ": ["bar"], + "stopwords_path": "/path/to/stopwords", + "type": "arabic" + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/PatternAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/PatternAnalyzerTest.json new file mode 100644 index 00000000000..9ce51b68a55 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/PatternAnalyzerTest.json @@ -0,0 +1,16 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "whitespace": { + "lowercase": false, + "pattern": "\\\\s+", + "flags": "g", + "type": "pattern" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SimpleAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SimpleAnalyzerTest.json new file mode 100644 index 00000000000..2f730ff5edb --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SimpleAnalyzerTest.json @@ -0,0 +1,13 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "simple": { + "type": "simple" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SnowballAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SnowballAnalyzerTest.json new file mode 100644 index 00000000000..e4e726dffe6 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/SnowballAnalyzerTest.json @@ -0,0 +1,15 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "snowball": { + "language": "English", + "stopwords": "these,are,some,stopwords", + "type": "snowball" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StandardAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StandardAnalyzerTest.json new file mode 100644 index 00000000000..dba6897d63d --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StandardAnalyzerTest.json @@ -0,0 +1,13 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "standard": { + "type": "standard" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StopAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StopAnalyzerTest.json new file mode 100644 index 00000000000..1e91c20638e --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/StopAnalyzerTest.json @@ -0,0 +1,15 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "stop": { + "stopwords": ["these","are","some","stopwords"], + "stopwords_path": "/path/to/stopwords", + "type": "stop" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/WhitespaceAnalyzerTest.json b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/WhitespaceAnalyzerTest.json new file mode 100644 index 00000000000..4e56223ff41 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Core/Indices/Analysis/Analyzers/WhitespaceAnalyzerTest.json @@ -0,0 +1,13 @@ +{ + "settings": { + "index": { + "analysis": { + "analyzer": { + "whitespace": { + "type": "whitespace" + } + } + } + } + } +} diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 915a64c4f8c..2bb08ed4cbc 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -120,7 +120,18 @@ + + + Always + + + + + + + + Always @@ -961,6 +972,9 @@ Always + + +