-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Currently, I only have 2 functions but I will be adding approximately 8 more in the near future and I want the code to look clean for the next person that comes along. I know I can set it up like the following:
.Functions (
freshness => freshnessEnabled ? freshness.Gauss(l => l.creationDate, d => d.Decay(.9).Offset("7d").Orgin(orginFreshness).Scale("3d") : null,
distance => distanceEnabled ? distance.Gauss(l => l.location, d => d.Decay(.9).Offset("10mi").Orgin(orginDistance).Scale("10mi") : null
)
I want to know if there is a way to do this by passing a list/array into Functions so that I can make my method look clean after I have 10 functions. Plus I will have a lot of conditional logic that will turn the individual functions on and off:
private List<FunctionScoreFunction> GetFunctions(){
var list = new List<FunctionScoreFunction>();
if (freshnessEnabled)
list.Add(new GaussFunction<Document>(l => l.creationDate, d => d.Decay(.9).Offset("7d").Orgin(orginFreshness).Scale("3d");
if (distanceEnabled)
list.Add(new GaussFunction<Document>(l => l.creationDate, d => d.Decay(.9).Offset("10mi").Orgin(orginDistance).Scale("10mi");
return list;
}
public Results Search (){
....
var functions = GetFunctions();
.Functions( functions)
....
}
Metadata
Metadata
Assignees
Labels
No labels