mirror of https://github.com/apache/lucene.git
SOLR-966 -- Enhance the map function query to take in an optional default value
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@740445 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d707212bbf
commit
522a5bed44
|
@ -143,6 +143,8 @@ New Features
|
||||||
|
|
||||||
31. SOLR-763: Add support for Lucene's PositionFilter (Mck SembWever via shalin)
|
31. SOLR-763: Add support for Lucene's PositionFilter (Mck SembWever via shalin)
|
||||||
|
|
||||||
|
32. SOLR-966: Enhance the map() function query to take in an optional default value (Noble Paul, shalin)
|
||||||
|
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
@ -160,7 +160,8 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin
|
||||||
float min = fp.parseFloat();
|
float min = fp.parseFloat();
|
||||||
float max = fp.parseFloat();
|
float max = fp.parseFloat();
|
||||||
float target = fp.parseFloat();
|
float target = fp.parseFloat();
|
||||||
return new RangeMapFloatFunction(source,min,max,target);
|
Float def = fp.hasMoreArguments() ? fp.parseFloat() : null;
|
||||||
|
return new RangeMapFloatFunction(source,min,max,target,def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(NamedList args) {
|
public void init(NamedList args) {
|
||||||
|
|
|
@ -34,12 +34,14 @@ public class RangeMapFloatFunction extends ValueSource {
|
||||||
protected final float min;
|
protected final float min;
|
||||||
protected final float max;
|
protected final float max;
|
||||||
protected final float target;
|
protected final float target;
|
||||||
|
protected final Float defaultVal;
|
||||||
|
|
||||||
public RangeMapFloatFunction(ValueSource source, float min, float max, float target) {
|
public RangeMapFloatFunction(ValueSource source, float min, float max, float target, Float def) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.defaultVal = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String description() {
|
public String description() {
|
||||||
|
@ -51,7 +53,7 @@ public class RangeMapFloatFunction extends ValueSource {
|
||||||
return new DocValues() {
|
return new DocValues() {
|
||||||
public float floatVal(int doc) {
|
public float floatVal(int doc) {
|
||||||
float val = vals.floatVal(doc);
|
float val = vals.floatVal(doc);
|
||||||
return (val>=min && val<=max) ? target : val;
|
return (val>=min && val<=max) ? target : (defaultVal == null ? val : defaultVal);
|
||||||
}
|
}
|
||||||
public int intVal(int doc) {
|
public int intVal(int doc) {
|
||||||
return (int)floatVal(doc);
|
return (int)floatVal(doc);
|
||||||
|
@ -74,11 +76,13 @@ public class RangeMapFloatFunction extends ValueSource {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int h = source.hashCode();
|
int h = source.hashCode();
|
||||||
h ^= (h << 10) | (h >>> 23);
|
h ^= (h << 10) | (h >>> 23);
|
||||||
Float.floatToIntBits(min);
|
h += Float.floatToIntBits(min);
|
||||||
h ^= (h << 14) | (h >>> 19);
|
h ^= (h << 14) | (h >>> 19);
|
||||||
h += Float.floatToIntBits(max);
|
h += Float.floatToIntBits(max);
|
||||||
h ^= (h << 13) | (h >>> 20);
|
h ^= (h << 13) | (h >>> 20);
|
||||||
h += Float.floatToIntBits(target);
|
h += Float.floatToIntBits(target);
|
||||||
|
if (defaultVal != null)
|
||||||
|
h += defaultVal.hashCode();
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +92,7 @@ public class RangeMapFloatFunction extends ValueSource {
|
||||||
return this.min == other.min
|
return this.min == other.min
|
||||||
&& this.max == other.max
|
&& this.max == other.max
|
||||||
&& this.target == other.target
|
&& this.target == other.target
|
||||||
&& this.source.equals(other.source);
|
&& this.source.equals(other.source)
|
||||||
|
&& (this.defaultVal == other.defaultVal || (this.defaultVal != null && this.defaultVal.equals(other.defaultVal)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue