2.3.3 中 FunctionScoreFunctionsDescriptor 和 FunctionScoreFunction 的等效类型是什么
What are the equivalent types for FunctionScoreFunctionsDescriptor & FunctionScoreFunction in 2.3.3
正在从 NEST 1.6.2 升级到 2.3.3。
NEST 2.3.3 中 FunctionScoreFunctionsDescriptor
和 FunctionScoreFunction
的新类型是什么?
他们是 FunctionScoreFunctionsDescriptor
-> ScoreFunctionsDescriptor
并且
FunctionScoreFunction
-> ScoreFunctionsDescriptor
?
如果是这样,我们构建一个 var functionScores = new List<Func<ScoreFunctionsDescriptor<IndexData>, ScoreFunctionsDescriptor<Property>>>()
,但我们如何将其传递给
var searchDescriptor = new SearchDescriptor<IndexData>()
.Paged(pageable)
.Query(q => q
.FunctionScore(fs => fs.Functions(***How do we pass the functionScores***));
我们可以像下面这样构建它吗?
functionScores.ForEach(f => searchDescriptor.Query(q => q.FunctionScore(fc => fc.Functions(f))));
function_score
查询可以采用 IEnumerable<IScoreFunction>
或 Func<ScoreFunctionsDescriptor<T>, IPromise<IList<IScoreFunction>>>
,即采用分数描述符和 return 函数列表的函数。 ScoreFunctionsDescriptor<T>
实现 IPromise<IList<IScoreFunction>>
基于此,如果我们想把一堆函数聚合在一起,我们可以把一堆函数聚合过来,一个ScoreFunctionsDescriptor<T>
和return一个ScoreFunctionsDescriptor<T>
public class Document
{
public string Name { get; set;}
public GeoLocation Location { get; set;}
}
var functions = new List<Func<ScoreFunctionsDescriptor<Document>, ScoreFunctionsDescriptor<Document>>>
{
s => s.FieldValueFactor(fvf => fvf
.Field(f => f.Name).Weight(3)),
s => s.ExponentialGeoLocation(geo => geo
.Field(f => f.Location)
.Offset("1km")
.Origin(new GeoLocation(-33.87189, 151.21623))
.Scale("2km")
)
};
client.Search<Document>(s => s
.Query(q => q
.FunctionScore(fs => fs
.Functions(sc => functions.Aggregate(sc, (a,f) => f(a)))
)
)
);
在这个例子中产生
{
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "name"
},
"weight": 3.0
},
{
"exp": {
"location": {
"origin": {
"lat": -33.87189,
"lon": 151.21623
},
"scale": "2.0km",
"offset": "1.0km"
}
}
}
]
}
}
}
正在从 NEST 1.6.2 升级到 2.3.3。
NEST 2.3.3 中 FunctionScoreFunctionsDescriptor
和 FunctionScoreFunction
的新类型是什么?
他们是 FunctionScoreFunctionsDescriptor
-> ScoreFunctionsDescriptor
并且
FunctionScoreFunction
-> ScoreFunctionsDescriptor
?
如果是这样,我们构建一个 var functionScores = new List<Func<ScoreFunctionsDescriptor<IndexData>, ScoreFunctionsDescriptor<Property>>>()
,但我们如何将其传递给
var searchDescriptor = new SearchDescriptor<IndexData>()
.Paged(pageable)
.Query(q => q
.FunctionScore(fs => fs.Functions(***How do we pass the functionScores***));
我们可以像下面这样构建它吗?
functionScores.ForEach(f => searchDescriptor.Query(q => q.FunctionScore(fc => fc.Functions(f))));
function_score
查询可以采用 IEnumerable<IScoreFunction>
或 Func<ScoreFunctionsDescriptor<T>, IPromise<IList<IScoreFunction>>>
,即采用分数描述符和 return 函数列表的函数。 ScoreFunctionsDescriptor<T>
实现 IPromise<IList<IScoreFunction>>
基于此,如果我们想把一堆函数聚合在一起,我们可以把一堆函数聚合过来,一个ScoreFunctionsDescriptor<T>
和return一个ScoreFunctionsDescriptor<T>
public class Document
{
public string Name { get; set;}
public GeoLocation Location { get; set;}
}
var functions = new List<Func<ScoreFunctionsDescriptor<Document>, ScoreFunctionsDescriptor<Document>>>
{
s => s.FieldValueFactor(fvf => fvf
.Field(f => f.Name).Weight(3)),
s => s.ExponentialGeoLocation(geo => geo
.Field(f => f.Location)
.Offset("1km")
.Origin(new GeoLocation(-33.87189, 151.21623))
.Scale("2km")
)
};
client.Search<Document>(s => s
.Query(q => q
.FunctionScore(fs => fs
.Functions(sc => functions.Aggregate(sc, (a,f) => f(a)))
)
)
);
在这个例子中产生
{
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "name"
},
"weight": 3.0
},
{
"exp": {
"location": {
"origin": {
"lat": -33.87189,
"lon": 151.21623
},
"scale": "2.0km",
"offset": "1.0km"
}
}
}
]
}
}
}