Skip to content

Commit da0b4f8

Browse files
committed
String overloads for decay function fields
1 parent 9d408a6 commit da0b4f8

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

src/Nest/DSL/Query/Functions/ExpFunction.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ public ExpFunction(Expression<Func<T, object>> objectPath, Action<FunctionScoreD
2121
descriptorBuilder(descriptor);
2222
_ExpDescriptor[objectPath] = descriptor;
2323
}
24+
25+
public ExpFunction(string field, Action<FunctionScoreDecayFieldDescriptor> descriptorBuilder)
26+
{
27+
_ExpDescriptor = new Dictionary<PropertyPathMarker, FunctionScoreDecayFieldDescriptor>();
28+
29+
var descriptor = new FunctionScoreDecayFieldDescriptor();
30+
descriptorBuilder(descriptor);
31+
_ExpDescriptor[field] = descriptor;
32+
}
2433
}
2534
}

src/Nest/DSL/Query/Functions/FunctionScoreFunctionsDescriptor.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@ public FunctionScoreFunctionsDescriptor()
1616
this._Functions = new List<FunctionScoreFunction<T>>();
1717
}
1818

19+
public FunctionScoreFunction<T> Gauss(string field, Action<FunctionScoreDecayFieldDescriptor> db)
20+
{
21+
var fn = new GaussFunction<T>(field, db);
22+
this._Functions.Add(fn);
23+
return fn;
24+
}
25+
1926
public FunctionScoreFunction<T> Gauss(Expression<Func<T, object>> objectPath, Action<FunctionScoreDecayFieldDescriptor> db)
2027
{
2128
var fn = new GaussFunction<T>(objectPath, db);
2229
this._Functions.Add(fn);
2330
return fn;
2431
}
2532

33+
public FunctionScoreFunction<T> Linear(string field, Action<FunctionScoreDecayFieldDescriptor> db)
34+
{
35+
var fn = new LinearFunction<T>(field, db);
36+
this._Functions.Add(fn);
37+
return fn;
38+
}
39+
2640
public FunctionScoreFunction<T> Linear(Expression<Func<T, object>> objectPath, Action<FunctionScoreDecayFieldDescriptor> db)
2741
{
2842
var fn = new LinearFunction<T>(objectPath, db);
2943
this._Functions.Add(fn);
3044
return fn;
3145
}
3246

47+
public FunctionScoreFunction<T> Exp(string field, Action<FunctionScoreDecayFieldDescriptor> db)
48+
{
49+
var fn = new ExpFunction<T>(field, db);
50+
this._Functions.Add(fn);
51+
return fn;
52+
}
53+
3354
public FunctionScoreFunction<T> Exp(Expression<Func<T, object>> objectPath, Action<FunctionScoreDecayFieldDescriptor> db)
3455
{
3556
var fn = new ExpFunction<T>(objectPath, db);

src/Nest/DSL/Query/Functions/GaussFunction.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ public GaussFunction(Expression<Func<T, object>> objectPath, Action<FunctionScor
2121
descriptorBuilder(descriptor);
2222
_GaussDescriptor[objectPath] = descriptor;
2323
}
24+
25+
public GaussFunction(string field, Action<FunctionScoreDecayFieldDescriptor> descriptorBuilder)
26+
{
27+
_GaussDescriptor = new Dictionary<PropertyPathMarker, FunctionScoreDecayFieldDescriptor>();
28+
29+
var descriptor = new FunctionScoreDecayFieldDescriptor();
30+
descriptorBuilder(descriptor);
31+
_GaussDescriptor[field] = descriptor;
32+
}
2433
}
2534
}

src/Nest/DSL/Query/Functions/LinearFunction.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ public LinearFunction(Expression<Func<T, object>> objectPath, Action<FunctionSco
2121
descriptorBuilder(descriptor);
2222
_LinearDescriptor[objectPath] = descriptor;
2323
}
24+
25+
public LinearFunction(string field, Action<FunctionScoreDecayFieldDescriptor> descriptorBuilder)
26+
{
27+
_LinearDescriptor = new Dictionary<PropertyPathMarker, FunctionScoreDecayFieldDescriptor>();
28+
29+
var descriptor = new FunctionScoreDecayFieldDescriptor();
30+
descriptorBuilder(descriptor);
31+
_LinearDescriptor[field] = descriptor;
32+
}
2433
}
2534
}

src/Tests/Nest.Tests.Unit/Search/Sorting/FunctionScoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void TestDecayFunctionWithFilter()
169169
var s = new SearchDescriptor<ElasticsearchProject>().Query(
170170
q => q.FunctionScore(
171171
fs => fs.Functions(
172-
f => f.Gauss(p => p.FloatValue, g => g.Origin("5").Scale("0.1"))
172+
f => f.Gauss("floatValue", g => g.Origin("5").Scale("0.1"))
173173
.Filter(gf => gf.Term("term1", "termValue")
174174
)
175175
)

0 commit comments

Comments
 (0)