ScoreFunctionsDescriptor

ScoreFunctionsDescriptor

从NEST 1.6.2升级到2.3.3。

NEST 2.3.3中FunctionScoreFunctionsDescriptorFunctionScoreFunction的新类型是什么?

他们是FunctionScoreFunctionsDescriptor-> ScoreFunctionsDescriptorFunctionScoreFunction-> 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>>>,即采用分数描述符并返回函数列表的函数。 ScoreFunctionsDescriptor<T>实现IPromise<IList<IScoreFunction>>
基于此,如果我们想将一堆函数聚合在一起,则可以对一堆函数进行聚合,这些函数采用ScoreFunctionsDescriptor<T>并返回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"
            }
          }
        }
      ]
    }
  }
}

关于elasticsearch - 2.3.3中的FunctionScoreFunctionsDescriptor和FunctionScoreFunction的等效类型是什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38158826/

10-11 05:03