Skip to content

Commit

Permalink
Mapping: When _all is disabled, optimize to not gather all entries, c…
Browse files Browse the repository at this point in the history
…loses elastic#722.
  • Loading branch information
kimchy committed Feb 26, 2011
1 parent be3e88d commit 9c24141
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
public interface AllFieldMapper extends FieldMapper<Void>, InternalMapper {

public static final String NAME = "_all";

/**
* Is the all field enabled or not.
*/
public boolean enabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected ByteFieldMapper(Names names, int precisionStep, Field.Index index, Fie
} else {
value = ((Number) externalValue).byteValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Byte.toString(value), boost);
}
} else {
Expand All @@ -169,12 +169,12 @@ protected ByteFieldMapper(Names names, int precisionStep, Field.Index index, Fie
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = (byte) context.parser().shortValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter
if (dateAsString == null) {
return null;
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), dateAsString, boost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected DoubleFieldMapper(Names names, int precisionStep,
} else {
value = ((Number) externalValue).doubleValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Double.toString(value), boost);
}
} else {
Expand All @@ -171,12 +171,12 @@ protected DoubleFieldMapper(Names names, int precisionStep,
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = context.parser().doubleValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected FloatFieldMapper(Names names, int precisionStep, Field.Index index, Fi
} else {
value = ((Number) externalValue).floatValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Float.toString(value), boost);
}
} else {
Expand All @@ -170,12 +170,12 @@ protected FloatFieldMapper(Names names, int precisionStep, Field.Index index, Fi
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = context.parser().floatValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected IntegerFieldMapper(Names names, int precisionStep, Field.Index index,
} else {
value = ((Number) externalValue).intValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Integer.toString(value), boost);
}
} else {
Expand All @@ -170,12 +170,12 @@ protected IntegerFieldMapper(Names names, int precisionStep, Field.Index index,
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = context.parser().intValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected LongFieldMapper(Names names, int precisionStep, Field.Index index, Fie
} else {
value = ((Number) externalValue).longValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Long.toString(value), boost);
}
} else {
Expand All @@ -170,12 +170,12 @@ protected LongFieldMapper(Names names, int precisionStep, Field.Index index, Fie
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = context.parser().longValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ public void uid(String 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() {
return this.allEntries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected ShortFieldMapper(Names names, int precisionStep, Field.Index index, Fi
} else {
value = ((Number) externalValue).shortValue();
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), Short.toString(value), boost);
}
} else {
Expand All @@ -170,12 +170,12 @@ protected ShortFieldMapper(Names names, int precisionStep, Field.Index index, Fi
return null;
}
value = nullValue;
if (nullValueAsString != null && (includeInAll == null || includeInAll)) {
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else {
value = context.parser().shortValue();
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), context.parser().text(), boost);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected StringFieldMapper(Names names, Field.Index index, Field.Store store, F
if (value == null) {
return null;
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), value, boost);
}
if (!indexed() && !stored()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected IpFieldMapper(Names names, int precisionStep,
if (ipAsString == null) {
return null;
}
if (includeInAll == null || includeInAll) {
if (context.includeInAll(includeInAll)) {
context.allEntries().addText(names.fullName(), ipAsString, boost);
}

Expand Down

0 comments on commit 9c24141

Please sign in to comment.