query/filter json parsing to allow passing numbers/booleans as strings and not native json types

This commit is contained in:
kimchy 2010-03-12 16:28:37 +02:00
parent 86c3a406c6
commit 471801b484
25 changed files with 283 additions and 67 deletions

View File

@ -7,6 +7,7 @@
<w>banon</w>
<w>birthdate</w>
<w>bool</w>
<w>booleans</w>
<w>checksum</w>
<w>commitable</w>
<w>committable</w>

View File

@ -22,6 +22,7 @@ package org.elasticsearch.http.netty;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.http.HttpRequest;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.SizeValue;
import org.elasticsearch.util.TimeValue;
import org.jboss.netty.buffer.ChannelBuffer;
@ -144,11 +145,7 @@ public class NettyHttpRequest implements HttpRequest {
}
@Override public boolean paramAsBoolean(String key, boolean defaultValue) {
String sValue = param(key);
if (sValue == null) {
return defaultValue;
}
return !(sValue.equals("false") || sValue.equals("0") || sValue.equals("off"));
return Booleans.parseBoolean(param(key), defaultValue);
}
@Override public Boolean paramAsBoolean(String key, Boolean defaultValue) {

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -38,7 +39,7 @@ import static com.google.common.collect.Lists.*;
import static org.elasticsearch.util.lucene.search.Queries.*;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -93,12 +94,22 @@ public class BoolJsonQueryParser extends AbstractIndexComponent implements JsonQ
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("disableCoord".equals(currentFieldName)) {
disableCoord = jp.getIntValue() != 0;
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("minimumNumberShouldMatch".equals(currentFieldName)) {
minimumNumberShouldMatch = jp.getIntValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
}
} else if (token == JsonToken.VALUE_STRING) {
if ("disableCoord".equals(currentFieldName)) {
disableCoord = Booleans.parseBoolean(jp.getText(), false);
} else if ("minimumNumberShouldMatch".equals(currentFieldName)) {
minimumNumberShouldMatch = Integer.parseInt(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
}
}
}

View File

@ -34,7 +34,7 @@ import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class ConstantScoreQueryJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -67,6 +67,10 @@ public class ConstantScoreQueryJsonQueryParser extends AbstractIndexComponent im
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
}
} else if (token == JsonToken.VALUE_STRING) {
if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
}
}
}
if (filter == null) {

View File

@ -74,11 +74,23 @@ public class DisMaxJsonQueryParser extends AbstractIndexComponent implements Jso
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
} else if ("tieBreakerMultiplier".equals(currentFieldName)) {
tieBreakerMultiplier = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
tieBreakerMultiplier = Float.parseFloat(jp.getText());
} else {
tieBreakerMultiplier = jp.getFloatValue();
}
} else if ("tieBreaker".equals(currentFieldName)) {
tieBreakerMultiplier = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
tieBreakerMultiplier = Float.parseFloat(jp.getText());
} else {
tieBreakerMultiplier = jp.getFloatValue();
}
}
}
}

View File

@ -33,6 +33,7 @@ import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.query.support.MapperQueryParser;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -80,29 +81,17 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else {
} else if (token == JsonToken.VALUE_STRING) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
boost = Float.parseFloat(jp.getText());
} else if ("enablePositionIncrements".equals(currentFieldName)) {
if (token == JsonToken.VALUE_TRUE) {
enablePositionIncrements = true;
} else if (token == JsonToken.VALUE_FALSE) {
enablePositionIncrements = false;
} else {
enablePositionIncrements = jp.getIntValue() != 0;
}
enablePositionIncrements = Booleans.parseBoolean(jp.getText(), true);
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
if (token == JsonToken.VALUE_TRUE) {
lowercaseExpandedTerms = true;
} else if (token == JsonToken.VALUE_FALSE) {
lowercaseExpandedTerms = false;
} else {
lowercaseExpandedTerms = jp.getIntValue() != 0;
}
lowercaseExpandedTerms = Booleans.parseBoolean(jp.getText(), true);
} else if ("phraseSlop".equals(currentFieldName)) {
phraseSlop = jp.getIntValue();
phraseSlop = Integer.parseInt(jp.getText());
} else if ("analyzer".equals(currentFieldName)) {
analyzer = analysisService.analyzer(jp.getText());
} else if ("defaultOperator".equals(currentFieldName)) {
@ -115,17 +104,57 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json
throw new QueryParsingException(index, "Query default operator [" + op + "] is not allowed");
}
} else if ("fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = jp.getFloatValue();
fuzzyMinSim = Float.parseFloat(jp.getText());
} else if ("fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = Integer.parseInt(jp.getText());
} else if ("escape".equals(currentFieldName)) {
escape = Booleans.parseBoolean(jp.getText(), false);
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = jp.getIntValue() != 0;
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = jp.getIntValue() != 0;
} else if ("phraseSlop".equals(currentFieldName)) {
phraseSlop = jp.getIntValue();
} else if ("fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = jp.getIntValue();
} else if ("fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = jp.getIntValue();
} else if ("escape".equals(currentFieldName)) {
if (token == JsonToken.VALUE_TRUE) {
escape = true;
} else if (token == JsonToken.VALUE_FALSE) {
escape = false;
} else {
escape = jp.getIntValue() != 0;
}
escape = jp.getIntValue() != 0;
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = jp.getIntValue();
}
} else if (token == JsonToken.VALUE_TRUE) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = true;
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = true;
} else if ("escape".equals(currentFieldName)) {
escape = true;
}
} else if (token == JsonToken.VALUE_FALSE) {
if ("query".equals(currentFieldName)) {
queryString = jp.getText();
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = false;
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = false;
} else if ("escape".equals(currentFieldName)) {
escape = false;
}
}
}

View File

@ -34,7 +34,7 @@ import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class FilteredQueryJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -66,6 +66,10 @@ public class FilteredQueryJsonQueryParser extends AbstractIndexComponent impleme
} else if ("filter".equals(currentFieldName)) {
filter = parseContext.parseInnerFilter();
}
} else if (token == JsonToken.VALUE_STRING) {
if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_NUMBER_INT || token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();

View File

@ -26,7 +26,7 @@ import org.elasticsearch.index.query.QueryParsingException;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public interface JsonFilterParser extends IndexComponent {

View File

@ -26,7 +26,7 @@ import org.elasticsearch.index.query.QueryParsingException;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public interface JsonQueryParser extends IndexComponent {

View File

@ -58,11 +58,15 @@ public class MatchAllJsonQueryParser extends AbstractIndexComponent implements J
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("normsField".equals(currentFieldName)) {
normsField = parseContext.indexName(jp.getText());
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
} else if ("normsField".equals(currentFieldName)) {
normsField = parseContext.indexName(jp.getText());
}
}
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.util.settings.Settings;
@ -72,6 +73,24 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
} else if (token == JsonToken.VALUE_STRING) {
if ("likeText".equals(currentFieldName)) {
mltQuery.setLikeText(jp.getText());
} else if ("minTermFrequency".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(Integer.parseInt(jp.getText()));
} else if ("maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(Integer.parseInt(jp.getText()));
} else if ("minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(Integer.parseInt(jp.getText()));
} else if ("maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(Integer.parseInt(jp.getText()));
} else if ("minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(Integer.parseInt(jp.getText()));
} else if ("maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
} else if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("minTermFrequency".equals(currentFieldName)) {

View File

@ -27,6 +27,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.util.settings.Settings;
@ -64,6 +65,24 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
} else if (token == JsonToken.VALUE_STRING) {
if ("likeText".equals(currentFieldName)) {
mltQuery.setLikeText(jp.getText());
} else if ("minTermFrequency".equals(currentFieldName)) {
mltQuery.setMinTermFrequency(Integer.parseInt(jp.getText()));
} else if ("maxQueryTerms".equals(currentFieldName)) {
mltQuery.setMaxQueryTerms(Integer.parseInt(jp.getText()));
} else if ("minDocFreq".equals(currentFieldName)) {
mltQuery.setMinDocFreq(Integer.parseInt(jp.getText()));
} else if ("maxDocFreq".equals(currentFieldName)) {
mltQuery.setMaxDocFreq(Integer.parseInt(jp.getText()));
} else if ("minWordLen".equals(currentFieldName)) {
mltQuery.setMinWordLen(Integer.parseInt(jp.getText()));
} else if ("maxWordLen".equals(currentFieldName)) {
mltQuery.setMaxWordLen(Integer.parseInt(jp.getText()));
} else if ("boostTerms".equals(currentFieldName)) {
mltQuery.setBoostTerms(Booleans.parseBoolean(jp.getText(), false));
} else if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(Float.parseFloat(jp.getText()));
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(Float.parseFloat(jp.getText()));
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("minTermFrequency".equals(currentFieldName)) {

View File

@ -38,7 +38,7 @@ import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.*;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class PrefixJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -68,10 +68,18 @@ public class PrefixJsonQueryParser extends AbstractIndexComponent implements Jso
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
currentFieldName = jp.getCurrentName();
} else {
} else if (token == JsonToken.VALUE_STRING) {
if (NAME.equals(currentFieldName)) {
value = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_NUMBER_INT) {
if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
}
}

View File

@ -35,6 +35,7 @@ import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.query.support.MapperQueryParser;
import org.elasticsearch.index.query.support.MultiFieldMapperQueryParser;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.trove.ExtTObjectFloatHashMap;
@ -134,6 +135,26 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement
}
} else if ("analyzer".equals(currentFieldName)) {
analyzer = analysisService.analyzer(jp.getText());
} else if ("allowLeadingWildcard".equals(currentFieldName)) {
allowLeadingWildcard = Booleans.parseBoolean(jp.getText(), false);
} else if ("lowercaseExpandedTerms".equals(currentFieldName)) {
lowercaseExpandedTerms = Booleans.parseBoolean(jp.getText(), false);
} else if ("enablePositionIncrements".equals(currentFieldName)) {
enablePositionIncrements = Booleans.parseBoolean(jp.getText(), false);
} else if ("escape".equals(currentFieldName)) {
escape = Booleans.parseBoolean(jp.getText(), false);
} else if ("useDisMax".equals(currentFieldName)) {
useDisMax = Booleans.parseBoolean(jp.getText(), false);
} else if ("fuzzyPrefixLength".equals(currentFieldName)) {
fuzzyPrefixLength = Integer.parseInt(jp.getText());
} else if ("phraseSlop".equals(currentFieldName)) {
phraseSlop = Integer.parseInt(jp.getText());
} else if ("fuzzyMinSim".equals(currentFieldName)) {
fuzzyMinSim = Float.parseFloat(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
} else if ("tieBreaker".equals(currentFieldName)) {
tieBreaker = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
if ("allowLeadingWildcard".equals(currentFieldName)) {

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -86,12 +87,16 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso
} else if ("includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
includeLower = Booleans.parseBoolean(jp.getText(), includeLower);
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
includeUpper = Booleans.parseBoolean(jp.getText(), includeUpper);
} else {
includeUpper = token == JsonToken.VALUE_TRUE;
}

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -36,7 +37,7 @@ import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.*;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class RangeJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -83,17 +84,25 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json
} else if ("includeLower".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeLower = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
includeLower = Booleans.parseBoolean(jp.getText(), includeLower);
} else {
includeLower = token == JsonToken.VALUE_TRUE;
}
} else if ("includeUpper".equals(currentFieldName)) {
if (token == JsonToken.VALUE_NUMBER_INT) {
includeUpper = jp.getIntValue() != 0;
} else if (token == JsonToken.VALUE_STRING) {
includeUpper = Booleans.parseBoolean(jp.getText(), includeUpper);
} else {
includeUpper = token == JsonToken.VALUE_TRUE;
}
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -71,9 +71,17 @@ public class SpanFirstJsonQueryParser extends AbstractIndexComponent implements
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
} else if ("end".equals(currentFieldName)) {
end = jp.getIntValue();
if (token == JsonToken.VALUE_STRING) {
end = Integer.parseInt(jp.getText());
} else {
end = jp.getIntValue();
}
}
}
}

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
@ -37,7 +38,7 @@ import java.util.List;
import static com.google.common.collect.Lists.*;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class SpanNearJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -76,6 +77,16 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
clauses.add((SpanQuery) query);
}
}
} else if (token == JsonToken.VALUE_STRING) {
if ("inOrder".equals(currentFieldName)) {
inOrder = Booleans.parseBoolean(jp.getText(), inOrder);
} else if ("collectPayloads".equals(currentFieldName)) {
collectPayloads = Booleans.parseBoolean(jp.getText(), collectPayloads);
} else if ("slop".equals(currentFieldName)) {
slop = Integer.parseInt(jp.getText());
} else if ("boost".equals(currentFieldName)) {
boost = Float.parseFloat(jp.getText());
}
} else if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
if ("inOrder".equals(currentFieldName)) {
inOrder = token == JsonToken.VALUE_TRUE;
@ -89,8 +100,10 @@ public class SpanNearJsonQueryParser extends AbstractIndexComponent implements J
collectPayloads = jp.getIntValue() != 0;
} else if ("slop".equals(currentFieldName)) {
slop = jp.getIntValue();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getIntValue();
}
} else {
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
}

View File

@ -34,7 +34,7 @@ import org.elasticsearch.util.settings.Settings;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class SpanNotJsonQueryParser extends AbstractIndexComponent implements JsonQueryParser {
@ -77,7 +77,11 @@ public class SpanNotJsonQueryParser extends AbstractIndexComponent implements Js
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -75,7 +75,11 @@ public class SpanOrJsonQueryParser extends AbstractIndexComponent implements Jso
}
} else {
if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -74,7 +74,11 @@ public class SpanTermJsonQueryParser extends AbstractIndexComponent implements J
if ("value".equals(currentFieldName)) {
value = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -70,7 +70,11 @@ public class TermJsonQueryParser extends AbstractIndexComponent implements JsonQ
if ("value".equals(currentFieldName)) {
value = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -72,7 +72,11 @@ public class WildcardJsonQueryParser extends AbstractIndexComponent implements J
if ("wildcard".equals(currentFieldName)) {
value = jp.getText();
} else if ("boost".equals(currentFieldName)) {
boost = jp.getFloatValue();
if (token == JsonToken.VALUE_STRING) {
boost = Float.parseFloat(jp.getText());
} else {
boost = jp.getFloatValue();
}
}
}
}

View File

@ -0,0 +1,40 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.util;
/**
* @author kimchy (shay.banon)
*/
public class Booleans {
public static boolean parseBoolean(String value, boolean defaultValue) {
if (value == null) {
return defaultValue;
}
return !(value.equals("false") || value.equals("0") || value.equals("off"));
}
public static Boolean parseBoolean(String value, Boolean defaultValue) {
if (value == null) {
return defaultValue;
}
return !(value.equals("false") || value.equals("0") || value.equals("off"));
}
}

View File

@ -152,15 +152,7 @@ public class ImmutableSettings implements Settings {
}
@Override public Boolean getAsBoolean(String setting, Boolean defaultValue) {
String sValue = get(setting);
if (sValue == null) {
return defaultValue;
}
try {
return sValue.equals("true") || sValue.equals("1");
} catch (NumberFormatException e) {
throw new SettingsException("Failed to parse boolean setting [" + setting + "] with value [" + sValue + "]", e);
}
return Booleans.parseBoolean(get(setting), defaultValue);
}
@Override public TimeValue getAsTime(String setting, TimeValue defaultValue) {