Skip to content

Commit 5cdd6fa

Browse files
committed
Merge pull request #964 from edwinf/add-string-double-fd-multimatch
Add string/double Fluent Dictionary Option to MultiMatchQuery
2 parents b4fba2d + a392697 commit 5cdd6fa

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/Nest/DSL/Query/MultiMatchQueryDescriptor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ public MultiMatchQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<Ex
140140
((IMultiMatchQuery)this).Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
141141
return this;
142142
}
143+
public MultiMatchQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<string, double?>> boostableSelector)
144+
{
145+
var d = new FluentDictionary<string, double?>();
146+
boostableSelector(d);
147+
((IMultiMatchQuery)this).Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
148+
return this;
149+
}
143150

144151
public MultiMatchQueryDescriptor<T> Query(string query)
145152
{

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@
886886
<None Include="Search\Query\Singles\GeoShape\GeoShapePolygon.json">
887887
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
888888
</None>
889+
<None Include="Search\Query\Singles\MultiMatch\TestMultiMatchOnFieldsWithBoost.json">
890+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
891+
</None>
889892
<None Include="Search\Query\Singles\MultiMatch\TestMultiMatchJson.json">
890893
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
891894
</None>

src/Tests/Nest.Tests.Unit/Search/Query/Singles/MultiMatch/MultiMatchJson.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@ public void TestMultiMatchJson()
2626
);
2727
this.JsonEquals(s, MethodInfo.GetCurrentMethod());
2828
}
29+
30+
[Test]
31+
public void TestMultiMatchOnFieldsWithBoost()
32+
{
33+
var s = new SearchDescriptor<ElasticsearchProject>()
34+
.From(0)
35+
.Size(10)
36+
.Query(q => q
37+
.MultiMatch(m => m
38+
.OnFieldsWithBoost(f=>f.Add("field1", 1.2).Add("field2",.9))
39+
.Query("this is a query")
40+
)
41+
);
42+
this.JsonEquals(s, MethodInfo.GetCurrentMethod());
43+
}
2944
}
3045
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"from": 0,
3+
"size": 10,
4+
"query": {
5+
"multi_match": {
6+
"query": "this is a query",
7+
"fields": [
8+
"field1^1.2",
9+
"field2^0.9"
10+
]
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)