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.analysis.Analyzer;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.elasticsearch.common.lucene.all.AllEntries; import org.elasticsearch.common.lucene.all.AllEntries;
import org.elasticsearch.common.util.concurrent.NotThreadSafe; import org.elasticsearch.common.util.concurrent.NotThreadSafe;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -216,16 +217,24 @@ public class ParseContext {
this.uid = uid; 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 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 * 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()) { if (!docMapper.allFieldMapper().enabled()) {
return false; return false;
} }
return specificIncludeInAll == null || specificIncludeInAll; // not explicitly set
if (specificIncludeInAll == null) {
return index != Field.Index.NO;
}
return specificIncludeInAll;
} }
public AllEntries allEntries() { public AllEntries allEntries() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -180,13 +180,13 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
long iValue = ipToLong(value); long iValue = ipToLong(value);
long iSim; long iSim;
try { try {
iSim = ipToLong(minSim); iSim = ipToLong(minSim);
} catch (ElasticSearchIllegalArgumentException e) { } catch (ElasticSearchIllegalArgumentException e) {
try { try {
iSim = Long.parseLong(minSim); iSim = Long.parseLong(minSim);
} catch (NumberFormatException e1) { } catch (NumberFormatException e1) {
iSim = (long) Double.parseDouble(minSim); iSim = (long) Double.parseDouble(minSim);
} }
} }
return NumericRangeQuery.newLongRange(names.indexName(), precisionStep, return NumericRangeQuery.newLongRange(names.indexName(), precisionStep,
iValue - iSim, iValue - iSim,
@ -237,7 +237,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
if (ipAsString == null) { if (ipAsString == null) {
return null; return null;
} }
if (context.includeInAll(includeInAll)) { if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(names.fullName(), ipAsString, boost); context.allEntries().addText(names.fullName(), ipAsString, boost);
} }