Skip to content

Commit f548698

Browse files
committed
Added unit tests for all analyzers
1 parent 83b7f59 commit f548698

11 files changed

+266
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"myCustom": {
7+
"tokenizer": "myTokenizer",
8+
"filter": [ "myTokenFilter1", "myTokenFilter2" ],
9+
"char_filter": [ "my_html" ],
10+
"alias": [ "alias1", "alias2" ],
11+
"type": "custom"
12+
}
13+
}
14+
}
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"keyword": {
7+
"type": "keyword"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"arabic": {
7+
"stopwords": ["foo"],
8+
"stem_exclusion ": ["bar"],
9+
"stopwords_path": "/path/to/stopwords",
10+
"type": "arabic"
11+
}
12+
}
13+
}
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"whitespace": {
7+
"lowercase": false,
8+
"pattern": "\\\\s+",
9+
"flags": "g",
10+
"type": "pattern"
11+
}
12+
}
13+
}
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"simple": {
7+
"type": "simple"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"snowball": {
7+
"language": "English",
8+
"stopwords": "these,are,some,stopwords",
9+
"type": "snowball"
10+
}
11+
}
12+
}
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"standard": {
7+
"type": "standard"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"stop": {
7+
"stopwords": ["these","are","some","stopwords"],
8+
"stopwords_path": "/path/to/stopwords",
9+
"type": "stop"
10+
}
11+
}
12+
}
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"index": {
4+
"analysis": {
5+
"analyzer": {
6+
"whitespace": {
7+
"type": "whitespace"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}

Diff for: src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,18 @@
120120
<Compile Include="Cluster\State\StateTests.cs" />
121121
<Compile Include="Core\Bulk\BulkTests.cs" />
122122
<Compile Include="Core\Bulk\BulkUrlTests.cs" />
123+
<Compile Include="Core\Indices\Analysis\Analyzers\AnalyzerTests.cs" />
123124
<Compile Include="Core\Map\MappingBehaviourTests.cs" />
125+
<None Include="Core\Indices\Analysis\Analyzers\CustomAnalyzerTest.json">
126+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
127+
</None>
128+
<None Include="Core\Indices\Analysis\Analyzers\StopAnalyzerTest.json" />
129+
<None Include="Core\Indices\Analysis\Analyzers\LanguageAnalyzerTest.json" />
130+
<None Include="Core\Indices\Analysis\Analyzers\WhitespaceAnalyzerTest.json" />
131+
<None Include="Core\Indices\Analysis\Analyzers\StandardAnalyzerTest.json" />
132+
<None Include="Core\Indices\Analysis\Analyzers\SnowballAnalyzerTest.json" />
133+
<None Include="Core\Indices\Analysis\Analyzers\SimpleAnalyzerTest.json" />
134+
<None Include="Core\Indices\Analysis\Analyzers\PatternAnalyzerTest.json" />
124135
<None Include="Core\Map\Properties\MultiFieldPropertyWithJustNamePath.json">
125136
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
126137
</None>
@@ -961,6 +972,9 @@
961972
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
962973
</None>
963974
</ItemGroup>
975+
<ItemGroup>
976+
<None Include="Core\Indices\Analysis\Analyzers\KeywordAnalyzerTest.json" />
977+
</ItemGroup>
964978
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
965979
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
966980
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)