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:
Igor Motov 2012-11-03 22:28:27 -04:00 committed by Shay Banon
parent 2fb3591792
commit 3f3a95668b
10 changed files with 17 additions and 15 deletions

View File

@ -81,7 +81,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
@Override @Override
public ByteFieldMapper build(BuilderContext context) { 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), ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context)); precisionStep, fuzzyFactor, boost, fieldType, nullValue, ignoreMalformed(context));
fieldMapper.includeInAll(includeInAll); fieldMapper.includeInAll(includeInAll);

View File

@ -109,7 +109,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
if (context.indexSettings() != null) { if (context.indexSettings() != null) {
parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE); 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, DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter,
precisionStep, fuzzyFactor, boost, fieldType, nullValue, precisionStep, fuzzyFactor, boost, fieldType, nullValue,
timeUnit, parseUpperInclusive, ignoreMalformed(context)); timeUnit, parseUpperInclusive, ignoreMalformed(context));

View File

@ -82,7 +82,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
@Override @Override
public DoubleFieldMapper build(BuilderContext context) { 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), DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, nullValue, precisionStep, fuzzyFactor, boost, fieldType, nullValue,
ignoreMalformed(context)); ignoreMalformed(context));

View File

@ -83,7 +83,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
@Override @Override
public FloatFieldMapper build(BuilderContext context) { 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), FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, nullValue, precisionStep, fuzzyFactor, boost, fieldType, nullValue,
ignoreMalformed(context)); ignoreMalformed(context));

View File

@ -83,7 +83,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
@Override @Override
public IntegerFieldMapper build(BuilderContext context) { 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), IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, precisionStep, fuzzyFactor, boost, fieldType,
nullValue, ignoreMalformed(context)); nullValue, ignoreMalformed(context));

View File

@ -83,7 +83,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
@Override @Override
public LongFieldMapper build(BuilderContext context) { 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), LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, nullValue, precisionStep, fuzzyFactor, boost, fieldType, nullValue,
ignoreMalformed(context)); ignoreMalformed(context));

View File

@ -83,7 +83,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
@Override @Override
public ShortFieldMapper build(BuilderContext context) { 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), ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context),
precisionStep, fuzzyFactor, boost, fieldType, nullValue, precisionStep, fuzzyFactor, boost, fieldType, nullValue,
ignoreMalformed(context)); ignoreMalformed(context));

View File

@ -53,6 +53,8 @@ public class TypeParsers {
builder.fuzzyFactor(propNode.toString()); builder.fuzzyFactor(propNode.toString());
} else if (propName.equals("ignore_malformed")) { } else if (propName.equals("ignore_malformed")) {
builder.ignoreMalformed(nodeBooleanValue(propNode)); builder.ignoreMalformed(nodeBooleanValue(propNode));
} else if (propName.equals("omit_norms")) {
builder.omitNorms(nodeBooleanValue(propNode));
} }
} }
} }

View File

@ -110,7 +110,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
@Override @Override
public IpFieldMapper build(BuilderContext context) { 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), IpFieldMapper fieldMapper = new IpFieldMapper(buildNames(context),
precisionStep, boost, fieldType, nullValue, ignoreMalformed(context)); precisionStep, boost, fieldType, nullValue, ignoreMalformed(context));
fieldMapper.includeInAll(includeInAll); fieldMapper.includeInAll(includeInAll);

View File

@ -35,13 +35,13 @@ public class CustomBoostMappingTests {
public void testCustomBoostValues() throws Exception { public void testCustomBoostValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("s_field").field("type", "string").endObject() .startObject("s_field").field("type", "string").endObject()
.startObject("l_field").field("type", "long").endObject() .startObject("l_field").field("type", "long").field("omit_norms", false).endObject()
.startObject("i_field").field("type", "integer").endObject() .startObject("i_field").field("type", "integer").field("omit_norms", false).endObject()
.startObject("sh_field").field("type", "short").endObject() .startObject("sh_field").field("type", "short").field("omit_norms", false).endObject()
.startObject("b_field").field("type", "byte").endObject() .startObject("b_field").field("type", "byte").field("omit_norms", false).endObject()
.startObject("d_field").field("type", "double").endObject() .startObject("d_field").field("type", "double").field("omit_norms", false).endObject()
.startObject("f_field").field("type", "float").endObject() .startObject("f_field").field("type", "float").field("omit_norms", false).endObject()
.startObject("date_field").field("type", "date").endObject() .startObject("date_field").field("type", "date").field("omit_norms", false).endObject()
.endObject().endObject().endObject().string(); .endObject().endObject().endObject().string();
DocumentMapper mapper = MapperTests.newParser().parse(mapping); DocumentMapper mapper = MapperTests.newParser().parse(mapping);