index: no should also disable include_in_all, closes #1087.

This commit is contained in:
Shay Banon 2011-08-19 19:51:39 +03:00
parent 0f0b41e4fa
commit ec6fa83856
10 changed files with 39 additions and 30 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.elasticsearch.common.lucene.all.AllEntries;
import org.elasticsearch.common.util.concurrent.NotThreadSafe;
import org.elasticsearch.common.xcontent.XContentParser;
@ -216,16 +217,24 @@ public class ParseContext {
this.uid = uid;
}
public boolean includeInAll(Boolean includeInAll, FieldMapper mapper) {
return includeInAll(includeInAll, mapper.index());
}
/**
* Is all included or not. Will always disable it if {@link org.elasticsearch.index.mapper.internal.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").
* its actual value (so, if not set, defaults to "true") and the field is indexed.
*/
public boolean includeInAll(Boolean specificIncludeInAll) {
private boolean includeInAll(Boolean specificIncludeInAll, Field.Index index) {
if (!docMapper.allFieldMapper().enabled()) {
return false;
}
return specificIncludeInAll == null || specificIncludeInAll;
// not explicitly set
if (specificIncludeInAll == null) {
return index != Field.Index.NO;
}
return specificIncludeInAll;
}
public AllEntries allEntries() {

View File

@ -192,7 +192,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
} else {
value = ((Number) externalValue).byteValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Byte.toString(value), boost);
}
} else {
@ -202,7 +202,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -229,7 +229,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
value = objValue;
} else {
value = (byte) parser.shortValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

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

View File

@ -188,7 +188,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
} else {
value = ((Number) externalValue).doubleValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Double.toString(value), boost);
}
} else {
@ -198,7 +198,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -225,7 +225,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
value = objValue;
} else {
value = parser.doubleValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

@ -187,7 +187,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
} else {
value = ((Number) externalValue).floatValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Float.toString(value), boost);
}
} else {
@ -197,7 +197,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -224,7 +224,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
value = objValue;
} else {
value = parser.floatValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

@ -192,7 +192,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
} else {
value = ((Number) externalValue).intValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Integer.toString(value), boost);
}
} else {
@ -202,7 +202,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -229,7 +229,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
value = objValue;
} else {
value = parser.intValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

@ -192,7 +192,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
} else {
value = ((Number) externalValue).longValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Long.toString(value), boost);
}
} else {
@ -202,7 +202,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -229,7 +229,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
value = objValue;
} else {
value = parser.longValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

@ -192,7 +192,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
} else {
value = ((Number) externalValue).shortValue();
}
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), Short.toString(value), boost);
}
} else {
@ -202,7 +202,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
return null;
}
value = nullValue;
if (nullValueAsString != null && (context.includeInAll(includeInAll))) {
if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
context.allEntries().addText(names.fullName(), nullValueAsString, boost);
}
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
@ -229,7 +229,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
value = objValue;
} else {
value = parser.shortValue();
if (context.includeInAll(includeInAll)) {
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), parser.text(), boost);
}
}

View File

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

View File

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