Mapping: When _all is disabled, optimize to not gather all entries, closes #722.

This commit is contained in:
kimchy 2011-02-26 04:16:03 +02:00
parent 24e95ea7e4
commit 4634ca5cb8
11 changed files with 38 additions and 21 deletions

View File

@ -25,4 +25,9 @@ package org.elasticsearch.index.mapper;
public interface AllFieldMapper extends FieldMapper<Void>, InternalMapper { public interface AllFieldMapper extends FieldMapper<Void>, InternalMapper {
public static final String NAME = "_all"; public static final String NAME = "_all";
/**
* Is the all field enabled or not.
*/
public boolean enabled();
} }

View File

@ -160,7 +160,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
} else { } else {
value = ((Number) externalValue).byteValue(); value = ((Number) externalValue).byteValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Byte.toString(value), boost); context.allEntries().addText(names.fullName(), Byte.toString(value), boost);
} }
} else { } else {
@ -169,12 +169,12 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = (byte) context.parser().shortValue(); value = (byte) context.parser().shortValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -194,7 +194,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
if (dateAsString == null) { if (dateAsString == null) {
return null; return null;
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), dateAsString, boost); context.allEntries().addText(names.fullName(), dateAsString, boost);
} }

View File

@ -162,7 +162,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
} else { } else {
value = ((Number) externalValue).doubleValue(); value = ((Number) externalValue).doubleValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Double.toString(value), boost); context.allEntries().addText(names.fullName(), Double.toString(value), boost);
} }
} else { } else {
@ -171,12 +171,12 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = context.parser().doubleValue(); value = context.parser().doubleValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -161,7 +161,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
} else { } else {
value = ((Number) externalValue).floatValue(); value = ((Number) externalValue).floatValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Float.toString(value), boost); context.allEntries().addText(names.fullName(), Float.toString(value), boost);
} }
} else { } else {
@ -170,12 +170,12 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = context.parser().floatValue(); value = context.parser().floatValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -161,7 +161,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
} else { } else {
value = ((Number) externalValue).intValue(); value = ((Number) externalValue).intValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Integer.toString(value), boost); context.allEntries().addText(names.fullName(), Integer.toString(value), boost);
} }
} else { } else {
@ -170,12 +170,12 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = context.parser().intValue(); value = context.parser().intValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -161,7 +161,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
} else { } else {
value = ((Number) externalValue).longValue(); value = ((Number) externalValue).longValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Long.toString(value), boost); context.allEntries().addText(names.fullName(), Long.toString(value), boost);
} }
} else { } else {
@ -170,12 +170,12 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = context.parser().longValue(); value = context.parser().longValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -199,6 +199,18 @@ public class ParseContext {
this.uid = uid; this.uid = uid;
} }
/**
* Is all included or not. Will always disable it if {@link org.elasticsearch.index.mapper.AllFieldMapper#enabled()}
* is <tt>false</tt>. If its enabled, then will return <tt>true</tt> only if the specific flag is <tt>null</tt> or
* its actual value (so, if not set, defaults to "true").
*/
public boolean includeInAll(Boolean specificIncludeInAll) {
if (!docMapper.allFieldMapper().enabled()) {
return false;
}
return specificIncludeInAll == null || specificIncludeInAll;
}
public AllEntries allEntries() { public AllEntries allEntries() {
return this.allEntries; return this.allEntries;
} }

View File

@ -161,7 +161,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
} else { } else {
value = ((Number) externalValue).shortValue(); value = ((Number) externalValue).shortValue();
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Short.toString(value), boost); context.allEntries().addText(names.fullName(), Short.toString(value), boost);
} }
} else { } else {
@ -170,12 +170,12 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
return null; return null;
} }
value = nullValue; value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) { if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost); context.allEntries().addText(names.fullName(), nullValueAsString, boost);
} }
} else { } else {
value = context.parser().shortValue(); value = context.parser().shortValue();
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost); context.allEntries().addText(names.fullName(), context.parser().text(), boost);
} }
} }

View File

@ -140,7 +140,7 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements In
if (value == null) { if (value == null) {
return null; return null;
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), value, boost); context.allEntries().addText(names.fullName(), value, boost);
} }
if (!indexed() && !stored()) { if (!indexed() && !stored()) {

View File

@ -210,7 +210,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
if (ipAsString == null) { if (ipAsString == null) {
return null; return null;
} }
if (includeInAll == null || includeInAll) { if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), ipAsString, boost); context.allEntries().addText(names.fullName(), ipAsString, boost);
} }