Skip to content

Commit 98fd73a

Browse files
committed
Can now map complex _all field mappings fluently
1 parent 88bc608 commit 98fd73a

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

src/Nest/DSL/PutMappingDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public PutMappingDescriptor<T> SetParent<K>() where K : class
9595
return this;
9696
}
9797

98-
public PutMappingDescriptor<T> DisableAllField(bool disabled = true)
98+
public PutMappingDescriptor<T> AllField(Func<AllFieldMapping, AllFieldMapping> allFieldSelector)
9999
{
100-
this._Mapping.AllFieldMapping = new AllFieldMapping().SetDisabled(disabled);
100+
this._Mapping.AllFieldMapping = allFieldSelector(new AllFieldMapping());
101101
return this;
102102
}
103103

src/Nest/Domain/Mapping/SpecialFields/AllFieldMapping.cs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,58 @@ namespace Nest
44
{
55
public class AllFieldMapping
66
{
7-
public AllFieldMapping()
7+
8+
[JsonProperty("enabled")]
9+
public bool? _Enabled { get; internal set; }
10+
11+
[JsonProperty("store")]
12+
public bool? _Store { get; internal set; }
13+
14+
[JsonProperty("term_vector")]
15+
public TermVectorOption? _TermVector { get; internal set; }
16+
17+
[JsonProperty("analyzer")]
18+
public string _Analyzer { get; internal set; }
19+
20+
[JsonProperty("index_analyzer")]
21+
public string _IndexAnalyzer { get; internal set; }
22+
23+
[JsonProperty("search_analyzer")]
24+
public string _SearchAnalyzer { get; internal set; }
25+
26+
public AllFieldMapping Enabled(bool enabled = true)
827
{
9-
this.Enabled = true;
28+
this._Enabled = enabled;
29+
return this;
1030
}
1131

12-
[JsonProperty("enabled")]
13-
public bool Enabled { get; internal set; }
32+
public AllFieldMapping Store(bool store = true)
33+
{
34+
this._Store = store;
35+
return this;
36+
}
37+
38+
public AllFieldMapping TermVector(TermVectorOption option)
39+
{
40+
this._TermVector = option;
41+
return this;
42+
}
43+
44+
public AllFieldMapping Analyzer(string analyzer)
45+
{
46+
this._Analyzer = analyzer;
47+
return this;
48+
}
49+
50+
public AllFieldMapping IndexAnalyzer(string analyzer)
51+
{
52+
this._IndexAnalyzer = analyzer;
53+
return this;
54+
}
1455

15-
public AllFieldMapping SetDisabled(bool disabled = true)
56+
public AllFieldMapping SearchAnalyzer(string analyzer)
1657
{
17-
this.Enabled = !disabled;
58+
this._SearchAnalyzer = analyzer;
1859
return this;
1960
}
2061
}

src/Tests/Nest.Tests.Integration/Core/Map/RootProperties/MapRootObjectPropertiesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void RootPropertiesShouldSerialize()
2020
.DateDetection(true)
2121
.NumericDetection(true)
2222
.SetParent<Person>() //makes no sense but i needed a type :)
23-
.DisableAllField(true)
23+
.AllField(a=>a.Enabled(false))
2424
.DisableIndexField(true)
2525
.DisableSizeField(true)
2626
.Dynamic()

src/Tests/Nest.Tests.Integration/Template/TemplateTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void PutTemplateWithMappings()
6565
.Template("donotinfluencothertests")
6666
.AddMapping<dynamic>(s=>s
6767
.Type("mytype")
68-
.DisableAllField()
68+
.AllField(a=>a.Enabled(false))
6969
)
7070
);
7171
Assert.IsTrue(putResponse.Acknowledged);
@@ -80,7 +80,7 @@ public void PutTemplateWithMappings()
8080

8181
Assert.IsTrue(mappings.ContainsKey("mytype"), "put-template-with-mappings template should have a `mytype` mapping");
8282
Assert.NotNull(mappings["mytype"].AllFieldMapping, "`mytype` mapping should contain the _all field mapping");
83-
Assert.AreEqual(false, mappings["mytype"].AllFieldMapping.Enabled, "_all { enabled } should be set to false");
83+
Assert.AreEqual(false, mappings["mytype"].AllFieldMapping._Enabled, "_all { enabled } should be set to false");
8484
}
8585

8686
[Test]

src/Tests/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ public void MapFluentFull()
3636
//Allows us to map the exceptions to the rule and be less verbose.
3737
.MapFromAttributes()
3838
.SetParent<Person>() //makes no sense but i needed a type :)
39-
.DisableAllField(false)
39+
.AllField(a=>a
40+
.Enabled()
41+
.IndexAnalyzer("nGram_analyzer")
42+
.SearchAnalyzer("whitespace_analyzer")
43+
.TermVector(TermVectorOption.with_positions_offsets)
44+
)
4045
.DisableIndexField(false)
4146
.DisableSizeField(false)
4247
.Dynamic()
@@ -87,6 +92,7 @@ public void MapFluentFull()
8792
.Add("attr1", "value1")
8893
.Add("attr2", new { attr3 = "value3" })
8994
)
95+
9096
.DynamicTemplates(d=>d
9197
.Add(t=>t
9298
.Name("template_1")
@@ -118,14 +124,8 @@ public void MapFluentFull()
118124
)
119125
)
120126
.Properties(props => props
121-
.String(s=>s
122-
.Name("_all")
123-
.IndexAnalyzer("nGram_analyzer")
124-
.SearchAnalyzer("whitespace_analyzer")
125-
)
126127
.String(s => s
127128
.Name(p => p.Name)
128-
129129
.IndexName("my_crazy_name_i_want_in_lucene")
130130
.IncludeInAll()
131131
.Index(FieldIndexOption.analyzed)

src/Tests/Nest.Tests.Unit/Core/Map/RootProperties/MapRootObjectPropertiesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void RootPropertiesShouldSerialize()
2222
.DateDetection(true)
2323
.NumericDetection(true)
2424
.SetParent<Person>() //makes no sense but i needed a type :)
25-
.DisableAllField(true)
25+
.AllField(a=>a.Enabled(false))
2626
.DisableIndexField(true)
2727
.DisableSizeField(true)
2828
.Dynamic()

0 commit comments

Comments
 (0)