rename scale_weight -> decay

This commit is contained in:
Britta Weber 2013-08-16 19:27:02 +02:00
parent 41b4a14933
commit 9e7ad7249f
7 changed files with 37 additions and 37 deletions

View File

@ -45,10 +45,10 @@ public interface DecayFunction {
*
* @param scale
* the raw scale value given by the user
* @param value
* @param decay
* the value which decay function should take once the distance
* reaches this scale
* */
public double processScale(double scale, double value);
public double processScale(double scale, double decay);
}

View File

@ -28,13 +28,13 @@ public abstract class DecayFunctionBuilder implements ScoreFunctionBuilder {
protected static final String REFERNECE = "reference";
protected static final String SCALE = "scale";
protected static final String SCALE_WEIGHT = "scale_weight";
protected static final String DECAY = "decay";
protected static final String OFFSET = "offset";
private String fieldName;
private Object reference;
private Object scale;
private double scaleWeight = -1;
private double decay = -1;
private Object offset;
public DecayFunctionBuilder(String fieldName, Object reference, Object scale) {
@ -43,11 +43,11 @@ public abstract class DecayFunctionBuilder implements ScoreFunctionBuilder {
this.scale = scale;
}
public DecayFunctionBuilder setScaleWeight(double scaleWeight) {
if (scaleWeight <= 0 || scaleWeight >= 1.0) {
public DecayFunctionBuilder setDecay(double decay) {
if (decay <= 0 || decay >= 1.0) {
throw new ElasticSearchIllegalStateException("scale weight parameter must be in range 0..1!");
}
this.scaleWeight = scaleWeight;
this.decay = decay;
return this;
}
@ -62,8 +62,8 @@ public abstract class DecayFunctionBuilder implements ScoreFunctionBuilder {
builder.startObject(fieldName);
builder.field(REFERNECE, reference);
builder.field(SCALE, scale);
if (scaleWeight > 0) {
builder.field(SCALE_WEIGHT, scaleWeight);
if (decay > 0) {
builder.field(DECAY, decay);
}
if (offset != null) {
builder.field(OFFSET, offset);

View File

@ -163,7 +163,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
String parameterName = null;
double scale = 0;
double reference = 0;
double scaleWeight = 0.5;
double decay = 0.5;
double offset = 0.0d;
boolean scaleFound = false;
boolean refFound = false;
@ -173,8 +173,8 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
} else if (parameterName.equals(DecayFunctionBuilder.SCALE)) {
scale = parser.doubleValue();
scaleFound = true;
} else if (parameterName.equals(DecayFunctionBuilder.SCALE_WEIGHT)) {
scaleWeight = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
decay = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.REFERNECE)) {
reference = parser.doubleValue();
refFound = true;
@ -189,7 +189,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
+ " must be set for numeric fields.");
}
IndexNumericFieldData<?> numericFieldData = parseContext.fieldData().getForField(mapper);
return new NumericFieldDataScoreFunction(reference, scale, scaleWeight, offset, getDecayFunction(), numericFieldData);
return new NumericFieldDataScoreFunction(reference, scale, decay, offset, getDecayFunction(), numericFieldData);
}
private ScoreFunction parseGeoVariable(String fieldName, XContentParser parser, QueryParseContext parseContext,
@ -199,7 +199,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
GeoPoint reference = new GeoPoint();
String scaleString = "1km";
String offsetString = "0km";
double scaleWeight = 0.5;
double decay = 0.5;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
parameterName = parser.currentName();
@ -207,8 +207,8 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
scaleString = parser.text();
} else if (parameterName.equals(DecayFunctionBuilder.REFERNECE)) {
reference = GeoPoint.parse(parser);
} else if (parameterName.equals(DecayFunctionBuilder.SCALE_WEIGHT)) {
scaleWeight = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
decay = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) {
offsetString = parser.text();
} else {
@ -221,7 +221,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
double scale = DistanceUnit.parse(scaleString, DistanceUnit.METERS, DistanceUnit.METERS);
double offset = DistanceUnit.parse(offsetString, DistanceUnit.METERS, DistanceUnit.METERS);
IndexGeoPointFieldData<?> indexFieldData = parseContext.fieldData().getForField(mapper);
return new GeoFieldDataScoreFunction(reference, scale, scaleWeight, offset, getDecayFunction(), indexFieldData);
return new GeoFieldDataScoreFunction(reference, scale, decay, offset, getDecayFunction(), indexFieldData);
}
@ -232,7 +232,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
String scaleString = null;
String referenceString = null;
String offsetString = "0d";
double scaleWeight = 0.5;
double decay = 0.5;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
parameterName = parser.currentName();
@ -240,8 +240,8 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
scaleString = parser.text();
} else if (parameterName.equals(DecayFunctionBuilder.REFERNECE)) {
referenceString = parser.text();
} else if (parameterName.equals(DecayFunctionBuilder.SCALE_WEIGHT)) {
scaleWeight = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
decay = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) {
offsetString = parser.text();
} else {
@ -261,7 +261,7 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
val = TimeValue.parseTimeValue(offsetString, TimeValue.timeValueHours(24));
double offset = val.getMillis();
IndexNumericFieldData<?> numericFieldData = parseContext.fieldData().getForField(dateFieldMapper);
return new NumericFieldDataScoreFunction(reference, scale, scaleWeight, offset, getDecayFunction(), numericFieldData);
return new NumericFieldDataScoreFunction(reference, scale, decay, offset, getDecayFunction(), numericFieldData);
}
static class GeoFieldDataScoreFunction extends AbstractDistanceScoreFunction {
@ -272,9 +272,9 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
private static final GeoDistance distFunction = GeoDistance.fromString("arc");
public GeoFieldDataScoreFunction(GeoPoint reference, double scale, double scaleWeight, double offset, DecayFunction func,
public GeoFieldDataScoreFunction(GeoPoint reference, double scale, double decay, double offset, DecayFunction func,
IndexGeoPointFieldData<?> fieldData) {
super(scale, scaleWeight, offset, func);
super(scale, decay, offset, func);
this.reference = reference;
this.fieldData = fieldData;
}
@ -315,9 +315,9 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
private final double reference;
private DoubleValues doubleValues;
public NumericFieldDataScoreFunction(double reference, double scale, double scaleWeight, double offset, DecayFunction func,
public NumericFieldDataScoreFunction(double reference, double scale, double decay, double offset, DecayFunction func,
IndexNumericFieldData<?> fieldData) {
super(scale, scaleWeight, offset, func);
super(scale, decay, offset, func);
this.fieldData = fieldData;
this.reference = reference;
}
@ -358,16 +358,16 @@ public abstract class DecayFunctionParser implements ScoreFunctionParser {
protected final double offset;
private final DecayFunction func;
public AbstractDistanceScoreFunction(double userSuppiedScale, double userSuppliedScaleWeight, double offset, DecayFunction func) {
public AbstractDistanceScoreFunction(double userSuppiedScale, double decay, double offset, DecayFunction func) {
super(CombineFunction.MULT);
if (userSuppiedScale <= 0.0) {
throw new ElasticSearchIllegalArgumentException(FunctionScoreQueryParser.NAME + " : scale must be > 0.0.");
}
if (userSuppliedScaleWeight <= 0.0 || userSuppliedScaleWeight >= 1.0) {
if (decay <= 0.0 || decay >= 1.0) {
throw new ElasticSearchIllegalArgumentException(FunctionScoreQueryParser.NAME
+ " : scale_weight must be in the range [0..1].");
+ " : decay must be in the range [0..1].");
}
this.scale = func.processScale(userSuppiedScale, userSuppliedScaleWeight);
this.scale = func.processScale(userSuppiedScale, decay);
this.func = func;
if (offset < 0.0d) {
throw new ElasticSearchIllegalArgumentException(FunctionScoreQueryParser.NAME + " : offset must be > 0.0");

View File

@ -56,8 +56,8 @@ public class ExponentialDecayFunctionParser extends DecayFunctionParser {
}
@Override
public double processScale(double scale, double value) {
return Math.log(value) / scale;
public double processScale(double scale, double decay) {
return Math.log(decay) / scale;
}
}

View File

@ -52,8 +52,8 @@ public class GaussDecayFunctionParser extends DecayFunctionParser {
}
@Override
public double processScale(double scale, double value) {
return 0.5 * Math.pow(scale, 2.0) / Math.log(value);
public double processScale(double scale, double decay) {
return 0.5 * Math.pow(scale, 2.0) / Math.log(decay);
}
}

View File

@ -56,8 +56,8 @@ public class LinearDecayFunctionParser extends DecayFunctionParser {
}
@Override
public double processScale(double scale, double value) {
return scale / (1.0 - value);
public double processScale(double scale, double decay) {
return scale / (1.0 - decay);
}
}

View File

@ -340,7 +340,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
indexRandom("test", false, builders);
refresh();
DecayFunctionBuilder fb = new GaussDecayFunctionBuilder("num", 0.0, 1.0).setScaleWeight(0.5);
DecayFunctionBuilder fb = new GaussDecayFunctionBuilder("num", 0.0, 1.0).setDecay(0.5);
// function score should return 0.5 for this function
ActionFuture<SearchResponse> response = client().search(
@ -448,7 +448,7 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test(expected = ElasticSearchIllegalStateException.class)
public void testExceptionThrownIfScaleRefNotBetween0And1() throws Exception {
DecayFunctionBuilder gfb = new GaussDecayFunctionBuilder("num1", "2013-05-28", "1d").setScaleWeight(100);
DecayFunctionBuilder gfb = new GaussDecayFunctionBuilder("num1", "2013-05-28", "1d").setDecay(100);
}