Skip to content

Commit

Permalink
Standardized use of “*_length” for parameter names rather than “*_len”.
Browse files Browse the repository at this point in the history
Java Builder apis drop old “len” methods in favour of new “length”
Rest APIs support both old “len: and new “length” forms using new ParseField class to a) provide compiler-checked consistency between Builder and Parser classes and
b) a common means of handling deprecated syntax in the DSL.
Documentation and rest specs only document the new “*length” forms
Closes #4083
  • Loading branch information
markharwood committed Jan 13, 2014
1 parent ed254b5 commit 2795f4e
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 157 deletions.
8 changes: 4 additions & 4 deletions docs/reference/query-dsl/queries/mlt-field-query.asciidoc
Expand Up @@ -51,11 +51,11 @@ not occur in at least this many docs. Defaults to `5`.
Words that appear in more than this many docs will be ignored. Defaults
to unbounded.

|`min_word_len` |The minimum word length below which words will be
ignored. Defaults to `0`.
|`min_word_length` |The minimum word length below which words will be
ignored. Defaults to `0`. (Old name "min_word_len" is deprecated)

|`max_word_len` |The maximum word length above which words will be
ignored. Defaults to unbounded (`0`).
|`max_word_length` |The maximum word length above which words will be
ignored. Defaults to unbounded (`0`). (Old name "max_word_len" is deprecated)

|`boost_terms` |Sets the boost factor to use when boosting terms.
Defaults to `1`.
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/query-dsl/queries/mlt-query.asciidoc
Expand Up @@ -50,11 +50,11 @@ not occur in at least this many docs. Defaults to `5`.
Words that appear in more than this many docs will be ignored. Defaults
to unbounded.

|`min_word_len` |The minimum word length below which words will be
ignored. Defaults to `0`.
|`min_word_length` |The minimum word length below which words will be
ignored. Defaults to `0`.(Old name "min_word_len" is deprecated)

|`max_word_len` |The maximum word length above which words will be
ignored. Defaults to unbounded (`0`).
|`max_word_length` |The maximum word length above which words will be
ignored. Defaults to unbounded (`0`). (Old name "max_word_len" is deprecated)

|`boost_terms` |Sets the boost factor to use when boosting terms.
Defaults to `1`.
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/search/suggesters/completion-suggest.asciidoc
Expand Up @@ -79,13 +79,13 @@ Mapping supports the following parameters:
`The Beatles`, no need to change a simple analyzer, if you are able to
enrich your data.

`max_input_len`::
`max_input_length`::
Limits the length of a single input, defaults to `50` UTF-16 code points.
This limit is only used at index time to reduce the total number of
characters per input string in order to prevent massive inputs from
bloating the underlying datastructure. The most usecases won't be influenced
by the default value since prefix completions hardly grow beyond prefixes longer
than a handful of characters.
than a handful of characters. (Old name "max_input_len" is deprecated)

[[indexing]]
==== Indexing
Expand Down
14 changes: 7 additions & 7 deletions docs/reference/search/suggesters/phrase-suggest.asciidoc
Expand Up @@ -36,7 +36,7 @@ curl -XPOST 'localhost:9200/_search' -d {
"direct_generator" : [ {
"field" : "body",
"suggest_mode" : "always",
"min_word_len" : 1
"min_word_length" : 1
} ],
"highlight": {
"pre_tag": "<em>",
Expand Down Expand Up @@ -229,15 +229,15 @@ The direct generators support the following parameters:
and 2. Any other value result in an bad request error being thrown.
Defaults to 2.

`prefix_len`::
`prefix_length`::
The number of minimal prefix characters that must
match in order be a candidate suggestions. Defaults to 1. Increasing
this number improves spellcheck performance. Usually misspellings don't
occur in the beginning of terms.
occur in the beginning of terms. (Old name "prefix_len" is deprecated)

`min_word_len`::
`min_word_length`::
The minimum length a suggest text term must have in
order to be included. Defaults to 4.
order to be included. Defaults to 4. (Old name "min_word_len" is deprecated)

`max_inspections`::
A factor that is used to multiply with the
Expand Down Expand Up @@ -298,11 +298,11 @@ curl -s -XPOST 'localhost:9200/_search' -d {
"direct_generator" : [ {
"field" : "body",
"suggest_mode" : "always",
"min_word_len" : 1
"min_word_length" : 1
}, {
"field" : "reverse",
"suggest_mode" : "always",
"min_word_len" : 1,
"min_word_length" : 1,
"pre_filter" : "reverse",
"post_filter" : "reverse"
} ]
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/search/suggesters/term-suggest.asciidoc
Expand Up @@ -62,15 +62,15 @@ doesn't take the query into account that is part of request.
between 1 and 2. Any other value result in an bad request error being
thrown. Defaults to 2.

`prefix_len`::
`prefix_length`::
The number of minimal prefix characters that must
match in order be a candidate suggestions. Defaults to 1. Increasing
this number improves spellcheck performance. Usually misspellings don't
occur in the beginning of terms.
occur in the beginning of terms. (Old name "prefix_len" is deprecated)

`min_word_len`::
`min_word_length`::
The minimum length a suggest text term must have in
order to be included. Defaults to 4.
order to be included. Defaults to 4. (Old name "min_word_len" is deprecated)

`shard_size`::
Sets the maximum number of suggestions to be retrieved
Expand Down
4 changes: 2 additions & 2 deletions rest-api-spec/api/mlt.json
Expand Up @@ -35,7 +35,7 @@
"type" : "number",
"description" : "The maximum query terms to be included in the generated query"
},
"max_word_len": {
"max_word_length": {
"type" : "number",
"description" : "The minimum length of the word: longer words will be ignored"
},
Expand All @@ -47,7 +47,7 @@
"type" : "number",
"description" : "The term frequency as percent: terms with lower occurence in the source document will be ignored"
},
"min_word_len": {
"min_word_length": {
"type" : "number",
"description" : "The minimum length of the word: shorter words will be ignored"
},
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java
Expand Up @@ -73,8 +73,8 @@ public class MoreLikeThisRequest extends ActionRequest<MoreLikeThisRequest> {
private String[] stopWords = null;
private int minDocFreq = -1;
private int maxDocFreq = -1;
private int minWordLen = -1;
private int maxWordLen = -1;
private int minWordLength = -1;
private int maxWordLength = -1;
private float boostTerms = -1;

private SearchType searchType = SearchType.DEFAULT;
Expand Down Expand Up @@ -275,31 +275,31 @@ public int maxDocFreq() {
/**
* The minimum word length below which words will be ignored. Defaults to <tt>0</tt>.
*/
public MoreLikeThisRequest minWordLen(int minWordLen) {
this.minWordLen = minWordLen;
public MoreLikeThisRequest minWordLength(int minWordLength) {
this.minWordLength = minWordLength;
return this;
}

/**
* The minimum word length below which words will be ignored. Defaults to <tt>0</tt>.
*/
public int minWordLen() {
return this.minWordLen;
public int minWordLength() {
return this.minWordLength;
}

/**
* The maximum word length above which words will be ignored. Defaults to unbounded.
*/
public MoreLikeThisRequest maxWordLen(int maxWordLen) {
this.maxWordLen = maxWordLen;
public MoreLikeThisRequest maxWordLength(int maxWordLength) {
this.maxWordLength = maxWordLength;
return this;
}

/**
* The maximum word length above which words will be ignored. Defaults to unbounded.
*/
public int maxWordLen() {
return this.maxWordLen;
public int maxWordLength() {
return this.maxWordLength;
}

/**
Expand Down Expand Up @@ -554,8 +554,8 @@ public void readFrom(StreamInput in) throws IOException {
}
minDocFreq = in.readVInt();
maxDocFreq = in.readVInt();
minWordLen = in.readVInt();
maxWordLen = in.readVInt();
minWordLength = in.readVInt();
maxWordLength = in.readVInt();
boostTerms = in.readFloat();
searchType = SearchType.fromId(in.readByte());
if (in.readBoolean()) {
Expand Down Expand Up @@ -625,8 +625,8 @@ public void writeTo(StreamOutput out) throws IOException {
}
out.writeVInt(minDocFreq);
out.writeVInt(maxDocFreq);
out.writeVInt(minWordLen);
out.writeVInt(maxWordLen);
out.writeVInt(minWordLength);
out.writeVInt(maxWordLength);
out.writeFloat(boostTerms);

out.writeByte(searchType.id());
Expand Down
Expand Up @@ -120,15 +120,15 @@ public MoreLikeThisRequestBuilder setMaxDocFreq(int maxDocFreq) {
* The minimum word length below which words will be ignored. Defaults to <tt>0</tt>.
*/
public MoreLikeThisRequestBuilder setMinWordLen(int minWordLen) {
request.minWordLen(minWordLen);
request.minWordLength(minWordLen);
return this;
}

/**
* The maximum word length above which words will be ignored. Defaults to unbounded.
*/
public MoreLikeThisRequestBuilder setMaxWordLen(int maxWordLen) {
request().maxWordLen(maxWordLen);
request().maxWordLength(maxWordLen);
return this;
}

Expand Down
Expand Up @@ -314,8 +314,8 @@ private void addMoreLikeThis(MoreLikeThisRequest request, BoolQueryBuilder boolB
.boostTerms(request.boostTerms())
.minDocFreq(request.minDocFreq())
.maxDocFreq(request.maxDocFreq())
.minWordLen(request.minWordLen())
.maxWordLen(request.maxWordLen())
.minWordLength(request.minWordLength())
.maxWordLen(request.maxWordLength())
.minTermFreq(request.minTermFreq())
.maxQueryTerms(request.maxQueryTerms())
.stopWords(request.stopWords())
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/elasticsearch/common/ParseField.java
Expand Up @@ -50,11 +50,19 @@ public ParseField(String value, String... deprecatedNames) {
this.deprecatedNames = set.toArray(new String[0]);
}
}

public String getPreferredName(){
return underscoreName;
}

public ParseField withDeprecation(String... deprecatedNames) {
return new ParseField(this.underscoreName, deprecatedNames);
}


public boolean match(String currentFieldName) {
return match(currentFieldName, EMPTY_FLAGS);
}

public boolean match(String currentFieldName, EnumSet<Flag> flags) {
if (currentFieldName.equals(camelCaseName) || currentFieldName.equals(underscoreName)) {
return true;
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.apache.lucene.search.suggest.analyzing.XAnalyzingSuggester;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
Expand Down Expand Up @@ -73,13 +74,13 @@ public static class Defaults extends AbstractFieldMapper.Defaults {
public static class Fields {
// Mapping field names
public static final String ANALYZER = "analyzer";
public static final String INDEX_ANALYZER = "index_analyzer";
public static final String SEARCH_ANALYZER = "search_analyzer";
public static final String PRESERVE_SEPARATORS = "preserve_separators";
public static final String PRESERVE_POSITION_INCREMENTS = "preserve_position_increments";
public static final ParseField INDEX_ANALYZER = new ParseField("index_analyzer");
public static final ParseField SEARCH_ANALYZER = new ParseField("search_analyzer");
public static final ParseField PRESERVE_SEPARATORS = new ParseField("preserve_separators");
public static final ParseField PRESERVE_POSITION_INCREMENTS = new ParseField("preserve_position_increments");
public static final String PAYLOADS = "payloads";
public static final String TYPE = "type";
public static final String MAX_INPUT_LENGTH = "max_input_len";
public static final ParseField MAX_INPUT_LENGTH = new ParseField("max_input_length", "max_input_len");
// Content field names
public static final String CONTENT_FIELD_NAME_INPUT = "input";
public static final String CONTENT_FIELD_NAME_OUTPUT = "output";
Expand Down Expand Up @@ -119,7 +120,7 @@ public Builder preservePositionIncrements(boolean preservePositionIncrements) {

public Builder maxInputLength(int maxInputLength) {
if (maxInputLength <= 0) {
throw new ElasticsearchIllegalArgumentException(Fields.MAX_INPUT_LENGTH + " must be > 0 but was [" + maxInputLength + "]");
throw new ElasticsearchIllegalArgumentException(Fields.MAX_INPUT_LENGTH.getPreferredName() + " must be > 0 but was [" + maxInputLength + "]");
}
this.maxInputLength = maxInputLength;
return this;
Expand Down Expand Up @@ -147,17 +148,17 @@ public static class TypeParser implements Mapper.TypeParser {
NamedAnalyzer analyzer = getNamedAnalyzer(parserContext, fieldNode.toString());
builder.indexAnalyzer(analyzer);
builder.searchAnalyzer(analyzer);
} else if (fieldName.equals(Fields.INDEX_ANALYZER) || fieldName.equals("indexAnalyzer")) {
} else if (Fields.INDEX_ANALYZER.match(fieldName)) {
builder.indexAnalyzer(getNamedAnalyzer(parserContext, fieldNode.toString()));
} else if (fieldName.equals(Fields.SEARCH_ANALYZER) || fieldName.equals("searchAnalyzer")) {
} else if (Fields.SEARCH_ANALYZER.match(fieldName)) {
builder.searchAnalyzer(getNamedAnalyzer(parserContext, fieldNode.toString()));
} else if (fieldName.equals(Fields.PAYLOADS)) {
builder.payloads(Boolean.parseBoolean(fieldNode.toString()));
} else if (fieldName.equals(Fields.PRESERVE_SEPARATORS) || fieldName.equals("preserveSeparators")) {
} else if (Fields.PRESERVE_SEPARATORS.match(fieldName)) {
builder.preserveSeparators(Boolean.parseBoolean(fieldNode.toString()));
} else if (fieldName.equals(Fields.PRESERVE_POSITION_INCREMENTS) || fieldName.equals("preservePositionIncrements")) {
} else if (Fields.PRESERVE_POSITION_INCREMENTS.match(fieldName)) {
builder.preservePositionIncrements(Boolean.parseBoolean(fieldNode.toString()));
} else if (fieldName.equals(Fields.MAX_INPUT_LENGTH) || fieldName.equals("maxInputLen")) {
} else if (Fields.MAX_INPUT_LENGTH.match(fieldName)) {
builder.maxInputLength(Integer.parseInt(fieldNode.toString()));
} else {
throw new MapperParsingException("Unknown field [" + fieldName + "]");
Expand Down Expand Up @@ -347,13 +348,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (indexAnalyzer.name().equals(searchAnalyzer.name())) {
builder.field(Fields.ANALYZER, indexAnalyzer.name());
} else {
builder.field(Fields.INDEX_ANALYZER, indexAnalyzer.name())
.field(Fields.SEARCH_ANALYZER, searchAnalyzer.name());
builder.field(Fields.INDEX_ANALYZER.getPreferredName(), indexAnalyzer.name())
.field(Fields.SEARCH_ANALYZER.getPreferredName(), searchAnalyzer.name());
}
builder.field(Fields.PAYLOADS, this.payloads);
builder.field(Fields.PRESERVE_SEPARATORS, this.preserveSeparators);
builder.field(Fields.PRESERVE_POSITION_INCREMENTS, this.preservePositionIncrements);
builder.field(Fields.MAX_INPUT_LENGTH, this.maxInputLength);
builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), this.preserveSeparators);
builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), this.preservePositionIncrements);
builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength);
return builder.endObject();
}

Expand Down

0 comments on commit 2795f4e

Please sign in to comment.