lucene4: add support for omit_norm setting to numeric types and don't omit norms if boost is not 1.0
This commit enables setting boost for numeric fields. However, there is still no way to take advantage of boosted numeric fields during searching because all queries against numeric fields are translated into range queries wrapped in ConstantScore. Boost for numeric fields is broken on master as well https://gist.github.com/7ecedea4f6a5219efb89
This commit is contained in:
parent
2fb3591792
commit
3f3a95668b
|
@ -81,7 +81,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
@Override
|
||||
public ByteFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
|
|
|
@ -109,7 +109,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
if (context.indexSettings() != null) {
|
||||
parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE);
|
||||
}
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter,
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
timeUnit, parseUpperInclusive, ignoreMalformed(context));
|
||||
|
|
|
@ -82,7 +82,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
|
||||
@Override
|
||||
public DoubleFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
|
|
|
@ -83,7 +83,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
@Override
|
||||
public FloatFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
|
|
|
@ -83,7 +83,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
@Override
|
||||
public IntegerFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType,
|
||||
nullValue, ignoreMalformed(context));
|
||||
|
|
|
@ -83,7 +83,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public LongFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost != 1.0f);
|
||||
LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
|
|
|
@ -83,7 +83,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
@Override
|
||||
public ShortFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, boost, fieldType, nullValue,
|
||||
ignoreMalformed(context));
|
||||
|
|
|
@ -53,6 +53,8 @@ public class TypeParsers {
|
|||
builder.fuzzyFactor(propNode.toString());
|
||||
} else if (propName.equals("ignore_malformed")) {
|
||||
builder.ignoreMalformed(nodeBooleanValue(propNode));
|
||||
} else if (propName.equals("omit_norms")) {
|
||||
builder.omitNorms(nodeBooleanValue(propNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
@Override
|
||||
public IpFieldMapper build(BuilderContext context) {
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() || boost != 1.0f);
|
||||
fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
|
||||
IpFieldMapper fieldMapper = new IpFieldMapper(buildNames(context),
|
||||
precisionStep, boost, fieldType, nullValue, ignoreMalformed(context));
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
|
|
|
@ -35,13 +35,13 @@ public class CustomBoostMappingTests {
|
|||
public void testCustomBoostValues() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("s_field").field("type", "string").endObject()
|
||||
.startObject("l_field").field("type", "long").endObject()
|
||||
.startObject("i_field").field("type", "integer").endObject()
|
||||
.startObject("sh_field").field("type", "short").endObject()
|
||||
.startObject("b_field").field("type", "byte").endObject()
|
||||
.startObject("d_field").field("type", "double").endObject()
|
||||
.startObject("f_field").field("type", "float").endObject()
|
||||
.startObject("date_field").field("type", "date").endObject()
|
||||
.startObject("l_field").field("type", "long").field("omit_norms", false).endObject()
|
||||
.startObject("i_field").field("type", "integer").field("omit_norms", false).endObject()
|
||||
.startObject("sh_field").field("type", "short").field("omit_norms", false).endObject()
|
||||
.startObject("b_field").field("type", "byte").field("omit_norms", false).endObject()
|
||||
.startObject("d_field").field("type", "double").field("omit_norms", false).endObject()
|
||||
.startObject("f_field").field("type", "float").field("omit_norms", false).endObject()
|
||||
.startObject("date_field").field("type", "date").field("omit_norms", false).endObject()
|
||||
.endObject().endObject().endObject().string();
|
||||
|
||||
DocumentMapper mapper = MapperTests.newParser().parse(mapping);
|
||||
|
|
Loading…
Reference in New Issue