Merge branch 'master' into move_refresh_into_index_service

This commit is contained in:
Simon Willnauer 2016-01-13 11:41:30 +01:00
commit 91289b8560
87 changed files with 1513 additions and 1073 deletions

View File

@ -309,9 +309,10 @@ class BuildPlugin implements Plugin<Project> {
/* /*
* -path because gradle will send in paths that don't always exist. * -path because gradle will send in paths that don't always exist.
* -missing because we have tons of missing @returns and @param. * -missing because we have tons of missing @returns and @param.
* -serial because we don't use java serialization.
*/ */
// don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :) // don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :)
options.compilerArgs << '-Werror' << '-Xlint:all,-path' << '-Xdoclint:all' << '-Xdoclint:-missing' options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial' << '-Xdoclint:all' << '-Xdoclint:-missing'
// compile with compact 3 profile by default // compile with compact 3 profile by default
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE // NOTE: this is just a compile time check: does not replace testing with a compact3 JRE
if (project.compactProfile != 'full') { if (project.compactProfile != 'full') {

View File

@ -62,6 +62,9 @@ public class ForbiddenPatternsTask extends DefaultTask {
patterns.put('nocommit', /nocommit/) patterns.put('nocommit', /nocommit/)
patterns.put('tab', /\t/) patterns.put('tab', /\t/)
patterns.put('wildcard imports', /^\s*import.*\.\*/) patterns.put('wildcard imports', /^\s*import.*\.\*/)
// We don't use Java serialization so we fail if it looks like we're trying to.
patterns.put('declares serialVersionUID', /serialVersionUID/)
patterns.put('references Serializable', /java\.io\.Serializable/)
inputs.property("excludes", filesFilter.excludes) inputs.property("excludes", filesFilter.excludes)
inputs.property("rules", patterns) inputs.property("rules", patterns)

View File

@ -23,6 +23,8 @@ import org.gradle.api.Project
import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Input import org.gradle.api.tasks.Input
import java.time.LocalDateTime
/** Configuration for an elasticsearch cluster, used for integration tests. */ /** Configuration for an elasticsearch cluster, used for integration tests. */
class ClusterConfiguration { class ClusterConfiguration {
@ -55,6 +57,7 @@ class ClusterConfiguration {
@Input @Input
Closure waitCondition = { NodeInfo node, AntBuilder ant -> Closure waitCondition = { NodeInfo node, AntBuilder ant ->
File tmpFile = new File(node.cwd, 'wait.success') File tmpFile = new File(node.cwd, 'wait.success')
ant.echo(message: "[${LocalDateTime.now()}] Waiting for elasticsearch node", level: "info")
ant.get(src: "http://${node.httpUri()}", ant.get(src: "http://${node.httpUri()}",
dest: tmpFile.toString(), dest: tmpFile.toString(),
ignoreerrors: true, // do not fail on error, so logging buffers can be flushed by the wait task ignoreerrors: true, // do not fail on error, so logging buffers can be flushed by the wait task

View File

@ -102,8 +102,8 @@ if (isEclipse) {
} }
} }
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-serial,-try,-unchecked" compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-serial,-try,-unchecked" compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
forbiddenPatterns { forbiddenPatterns {
exclude '**/*.json' exclude '**/*.json'

View File

@ -36,6 +36,7 @@ import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.lucene.util.ToStringUtils; import org.apache.lucene.util.ToStringUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -326,7 +327,7 @@ public abstract class BlendedTermQuery extends Query {
} }
if ((maxTermFrequency >= 1f && docFreqs[i] > maxTermFrequency) if ((maxTermFrequency >= 1f && docFreqs[i] > maxTermFrequency)
|| (docFreqs[i] > (int) Math.ceil(maxTermFrequency || (docFreqs[i] > (int) Math.ceil(maxTermFrequency
* (float) maxDoc))) { * maxDoc))) {
highBuilder.add(query, BooleanClause.Occur.SHOULD); highBuilder.add(query, BooleanClause.Occur.SHOULD);
} else { } else {
lowBuilder.add(query, BooleanClause.Occur.SHOULD); lowBuilder.add(query, BooleanClause.Occur.SHOULD);
@ -362,15 +363,15 @@ public abstract class BlendedTermQuery extends Query {
return new BlendedTermQuery(terms, boosts) { return new BlendedTermQuery(terms, boosts) {
@Override @Override
protected Query topLevelQuery(Term[] terms, TermContext[] ctx, int[] docFreqs, int maxDoc) { protected Query topLevelQuery(Term[] terms, TermContext[] ctx, int[] docFreqs, int maxDoc) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(tieBreakerMultiplier); List<Query> queries = new ArrayList<>(ctx.length);
for (int i = 0; i < terms.length; i++) { for (int i = 0; i < terms.length; i++) {
Query query = new TermQuery(terms[i], ctx[i]); Query query = new TermQuery(terms[i], ctx[i]);
if (boosts != null && boosts[i] != 1f) { if (boosts != null && boosts[i] != 1f) {
query = new BoostQuery(query, boosts[i]); query = new BoostQuery(query, boosts[i]);
} }
disMaxQuery.add(query); queries.add(query);
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, tieBreakerMultiplier);
} }
}; };
} }

View File

@ -142,19 +142,19 @@ public class MapperQueryParser extends QueryParser {
return getFieldQuerySingle(fields.iterator().next(), queryText, quoted); return getFieldQuerySingle(fields.iterator().next(), queryText, quoted);
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getFieldQuerySingle(mField, queryText, quoted); Query q = getFieldQuerySingle(mField, queryText, quoted);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -242,20 +242,20 @@ public class MapperQueryParser extends QueryParser {
Collection<String> fields = extractMultiFields(field); Collection<String> fields = extractMultiFields(field);
if (fields != null) { if (fields != null) {
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = super.getFieldQuery(mField, queryText, slop); Query q = super.getFieldQuery(mField, queryText, slop);
if (q != null) { if (q != null) {
added = true; added = true;
q = applySlop(q, slop); q = applySlop(q, slop);
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -295,19 +295,19 @@ public class MapperQueryParser extends QueryParser {
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getRangeQuerySingle(mField, part1, part2, startInclusive, endInclusive); Query q = getRangeQuerySingle(mField, part1, part2, startInclusive, endInclusive);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -359,19 +359,19 @@ public class MapperQueryParser extends QueryParser {
return getFuzzyQuerySingle(fields.iterator().next(), termStr, minSimilarity); return getFuzzyQuerySingle(fields.iterator().next(), termStr, minSimilarity);
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getFuzzyQuerySingle(mField, termStr, minSimilarity); Query q = getFuzzyQuerySingle(mField, termStr, minSimilarity);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -422,19 +422,19 @@ public class MapperQueryParser extends QueryParser {
return getPrefixQuerySingle(fields.iterator().next(), termStr); return getPrefixQuerySingle(fields.iterator().next(), termStr);
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getPrefixQuerySingle(mField, termStr); Query q = getPrefixQuerySingle(mField, termStr);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -552,19 +552,19 @@ public class MapperQueryParser extends QueryParser {
return getWildcardQuerySingle(fields.iterator().next(), termStr); return getWildcardQuerySingle(fields.iterator().next(), termStr);
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getWildcardQuerySingle(mField, termStr); Query q = getWildcardQuerySingle(mField, termStr);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {
@ -681,19 +681,19 @@ public class MapperQueryParser extends QueryParser {
return getRegexpQuerySingle(fields.iterator().next(), termStr); return getRegexpQuerySingle(fields.iterator().next(), termStr);
} }
if (settings.useDisMax()) { if (settings.useDisMax()) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(settings.tieBreaker()); List<Query> queries = new ArrayList<>();
boolean added = false; boolean added = false;
for (String mField : fields) { for (String mField : fields) {
Query q = getRegexpQuerySingle(mField, termStr); Query q = getRegexpQuerySingle(mField, termStr);
if (q != null) { if (q != null) {
added = true; added = true;
disMaxQuery.add(applyBoost(mField, q)); queries.add(applyBoost(mField, q));
} }
} }
if (!added) { if (!added) {
return null; return null;
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, settings.tieBreaker());
} else { } else {
List<BooleanClause> clauses = new ArrayList<>(); List<BooleanClause> clauses = new ArrayList<>();
for (String mField : fields) { for (String mField : fields) {

View File

@ -57,9 +57,6 @@ import java.security.BasicPermission;
* </code></pre> * </code></pre>
*/ */
public final class SpecialPermission extends BasicPermission { public final class SpecialPermission extends BasicPermission {
private static final long serialVersionUID = -4129500096157408168L;
/** /**
* Creates a new SpecialPermision object. * Creates a new SpecialPermision object.
*/ */

View File

@ -182,11 +182,10 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
searchContext.preProcess(); searchContext.preProcess();
valid = true; valid = true;
if (request.explain()) {
explanation = searchContext.parsedQuery().query().toString();
}
if (request.rewrite()) { if (request.rewrite()) {
explanation = getRewrittenQuery(searcher.searcher(), searchContext.query()); explanation = getRewrittenQuery(searcher.searcher(), searchContext.query());
} else if (request.explain()) {
explanation = searchContext.filteredQuery().query().toString();
} }
} catch (QueryShardException|ParsingException e) { } catch (QueryShardException|ParsingException e) {
valid = false; valid = false;

View File

@ -639,8 +639,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
ScriptParameterParser scriptParameterParser = new ScriptParameterParser(); ScriptParameterParser scriptParameterParser = new ScriptParameterParser();
Map<String, Object> scriptParams = null; Map<String, Object> scriptParams = null;
Script script = null; Script script = null;
XContentType xContentType = XContentFactory.xContentType(source); try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token == null) { if (token == null) {
return this; return this;
@ -657,10 +656,12 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
} else if ("scripted_upsert".equals(currentFieldName)) { } else if ("scripted_upsert".equals(currentFieldName)) {
scriptedUpsert = parser.booleanValue(); scriptedUpsert = parser.booleanValue();
} else if ("upsert".equals(currentFieldName)) { } else if ("upsert".equals(currentFieldName)) {
XContentType xContentType = XContentFactory.xContentType(source);
XContentBuilder builder = XContentFactory.contentBuilder(xContentType); XContentBuilder builder = XContentFactory.contentBuilder(xContentType);
builder.copyCurrentStructure(parser); builder.copyCurrentStructure(parser);
safeUpsertRequest().source(builder); safeUpsertRequest().source(builder);
} else if ("doc".equals(currentFieldName)) { } else if ("doc".equals(currentFieldName)) {
XContentType xContentType = XContentFactory.xContentType(source);
XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType); XContentBuilder docBuilder = XContentFactory.contentBuilder(xContentType);
docBuilder.copyCurrentStructure(parser); docBuilder.copyCurrentStructure(parser);
safeDoc().source(docBuilder); safeDoc().source(docBuilder);

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Circle; import com.spatial4j.core.shape.Circle;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.DistanceUnit;
@ -35,12 +36,20 @@ public class CircleBuilder extends ShapeBuilder {
public static final String FIELD_RADIUS = "radius"; public static final String FIELD_RADIUS = "radius";
public static final GeoShapeType TYPE = GeoShapeType.CIRCLE; public static final GeoShapeType TYPE = GeoShapeType.CIRCLE;
public static final CircleBuilder PROTOTYPE = new CircleBuilder(); static final CircleBuilder PROTOTYPE = new CircleBuilder();
private DistanceUnit unit; private DistanceUnit unit = DistanceUnit.DEFAULT;
private double radius; private double radius;
private Coordinate center; private Coordinate center;
/**
* Creates a circle centered at [0.0, 0.0].
* Center can be changed by calling {@link #center(Coordinate)} later.
*/
public CircleBuilder() {
this.center = ZERO_ZERO;
}
/** /**
* Set the center of the circle * Set the center of the circle
* *

View File

@ -20,26 +20,32 @@
package org.elasticsearch.common.geo.builders; package org.elasticsearch.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List;
/** /**
* The {@link PointCollection} is an abstract base implementation for all GeoShapes. It simply handles a set of points. * The {@link CoordinateCollection} is an abstract base implementation for {@link LineStringBuilder} and {@link MultiPointBuilder}.
* It holds a common list of {@link Coordinate}, provides setters for adding elements to the list and can render this to XContent.
*/ */
public abstract class PointCollection<E extends PointCollection<E>> extends ShapeBuilder { public abstract class CoordinateCollection<E extends CoordinateCollection<E>> extends ShapeBuilder {
protected final ArrayList<Coordinate> points; protected final List<Coordinate> coordinates;
protected PointCollection() { /**
this(new ArrayList<Coordinate>()); * Construct a new collection of coordinates.
} * @param coordinates an initial list of coordinates
* @throws IllegalArgumentException if coordinates is <tt>null</tt> or empty
protected PointCollection(ArrayList<Coordinate> points) { */
this.points = points; protected CoordinateCollection(List<Coordinate> coordinates) {
if (coordinates == null || coordinates.size() == 0) {
throw new IllegalArgumentException("cannot create point collection with empty set of points");
}
this.coordinates = coordinates;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -48,54 +54,54 @@ public abstract class PointCollection<E extends PointCollection<E>> extends Shap
} }
/** /**
* Add a new point to the collection * Add a new coordinate to the collection
* @param longitude longitude of the coordinate * @param longitude longitude of the coordinate
* @param latitude latitude of the coordinate * @param latitude latitude of the coordinate
* @return this * @return this
*/ */
public E point(double longitude, double latitude) { public E coordinate(double longitude, double latitude) {
return this.point(coordinate(longitude, latitude)); return this.coordinate(new Coordinate(longitude, latitude));
} }
/** /**
* Add a new point to the collection * Add a new coordinate to the collection
* @param coordinate coordinate of the point * @param coordinate coordinate of the point
* @return this * @return this
*/ */
public E point(Coordinate coordinate) { public E coordinate(Coordinate coordinate) {
this.points.add(coordinate); this.coordinates.add(coordinate);
return thisRef(); return thisRef();
} }
/** /**
* Add a array of points to the collection * Add a array of coordinates to the collection
* *
* @param coordinates array of {@link Coordinate}s to add * @param coordinates array of {@link Coordinate}s to add
* @return this * @return this
*/ */
public E points(Coordinate...coordinates) { public E coordinates(Coordinate...coordinates) {
return this.points(Arrays.asList(coordinates)); return this.coordinates(Arrays.asList(coordinates));
} }
/** /**
* Add a collection of points to the collection * Add a collection of coordinates to the collection
* *
* @param coordinates array of {@link Coordinate}s to add * @param coordinates array of {@link Coordinate}s to add
* @return this * @return this
*/ */
public E points(Collection<? extends Coordinate> coordinates) { public E coordinates(Collection<? extends Coordinate> coordinates) {
this.points.addAll(coordinates); this.coordinates.addAll(coordinates);
return thisRef(); return thisRef();
} }
/** /**
* Copy all points to a new Array * Copy all coordinate to a new Array
* *
* @param closed if set to true the first point of the array is repeated as last element * @param closed if set to true the first point of the array is repeated as last element
* @return Array of coordinates * @return Array of coordinates
*/ */
protected Coordinate[] coordinates(boolean closed) { protected Coordinate[] coordinates(boolean closed) {
Coordinate[] result = points.toArray(new Coordinate[points.size() + (closed?1:0)]); Coordinate[] result = coordinates.toArray(new Coordinate[coordinates.size() + (closed?1:0)]);
if(closed) { if(closed) {
result[result.length-1] = result[0]; result[result.length-1] = result[0];
} }
@ -111,14 +117,14 @@ public abstract class PointCollection<E extends PointCollection<E>> extends Shap
*/ */
protected XContentBuilder coordinatesToXcontent(XContentBuilder builder, boolean closed) throws IOException { protected XContentBuilder coordinatesToXcontent(XContentBuilder builder, boolean closed) throws IOException {
builder.startArray(); builder.startArray();
for(Coordinate point : points) { for(Coordinate coord : coordinates) {
toXContent(builder, point); toXContent(builder, coord);
} }
if(closed) { if(closed) {
Coordinate start = points.get(0); Coordinate start = coordinates.get(0);
Coordinate end = points.get(points.size()-1); Coordinate end = coordinates.get(coordinates.size()-1);
if(start.x != end.x || start.y != end.y) { if(start.x != end.x || start.y != end.y) {
toXContent(builder, points.get(0)); toXContent(builder, coordinates.get(0));
} }
} }
builder.endArray(); builder.endArray();

View File

@ -0,0 +1,98 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* A builder for a list of coordinates.
* Enables chaining of individual coordinates either as long/lat pairs
* or as {@link Coordinate} elements, arrays or collections.
*/
public class CoordinatesBuilder {
private final List<Coordinate> points = new ArrayList<>();
/**
* Add a new coordinate to the collection
* @param coordinate the coordinate to add
* @return this
*/
public CoordinatesBuilder coordinate(Coordinate coordinate) {
this.points.add(coordinate);
return this;
}
/**
* Add a new coordinate to the collection
* @param longitude longitude of the coordinate
* @param latitude latitude of the coordinate
* @return this
*/
public CoordinatesBuilder coordinate(double longitude, double latitude) {
return this.coordinate(new Coordinate(longitude, latitude));
}
/**
* Add an array of coordinates to the current coordinates
*
* @param coordinates array of {@link Coordinate}s to add
* @return this
*/
public CoordinatesBuilder coordinates(Coordinate...coordinates) {
return this.coordinates(Arrays.asList(coordinates));
}
/**
* Add a collection of coordinates to the current coordinates
*
* @param coordinates collection of {@link Coordinate}s to add
* @return this
*/
public CoordinatesBuilder coordinates(Collection<? extends Coordinate> coordinates) {
this.points.addAll(coordinates);
return this;
}
/**
* Makes a closed ring out of the current coordinates by adding the starting point as the end point.
* Will have no effect of starting and end point are already the same coordinate.
*/
public CoordinatesBuilder close() {
Coordinate start = points.get(0);
Coordinate end = points.get(points.size()-1);
if(start.x != end.x || start.y != end.y) {
points.add(start);
}
return this;
}
/**
* @return a list containing the current coordinates
*/
public List<Coordinate> build() {
return new ArrayList<>(this.points);
}
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Rectangle; import com.spatial4j.core.shape.Rectangle;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -32,33 +33,22 @@ public class EnvelopeBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.ENVELOPE; public static final GeoShapeType TYPE = GeoShapeType.ENVELOPE;
public static final EnvelopeBuilder PROTOTYPE = new EnvelopeBuilder(); static final EnvelopeBuilder PROTOTYPE = new EnvelopeBuilder(new Coordinate(-1.0, 1.0), new Coordinate(1.0, -1.0));
private Coordinate topLeft; private Coordinate topLeft;
private Coordinate bottomRight; private Coordinate bottomRight;
public EnvelopeBuilder topLeft(Coordinate topLeft) { public EnvelopeBuilder(Coordinate topLeft, Coordinate bottomRight) {
Objects.requireNonNull(topLeft, "topLeft of envelope cannot be null");
Objects.requireNonNull(bottomRight, "bottomRight of envelope cannot be null");
this.topLeft = topLeft; this.topLeft = topLeft;
return this; this.bottomRight = bottomRight;
}
public EnvelopeBuilder topLeft(double longitude, double latitude) {
return topLeft(coordinate(longitude, latitude));
} }
public Coordinate topLeft() { public Coordinate topLeft() {
return this.topLeft; return this.topLeft;
} }
public EnvelopeBuilder bottomRight(Coordinate bottomRight) {
this.bottomRight = bottomRight;
return this;
}
public EnvelopeBuilder bottomRight(double longitude, double latitude) {
return bottomRight(coordinate(longitude, latitude));
}
public Coordinate bottomRight() { public Coordinate bottomRight() {
return this.bottomRight; return this.bottomRight;
} }
@ -110,8 +100,6 @@ public class EnvelopeBuilder extends ShapeBuilder {
@Override @Override
public EnvelopeBuilder readFrom(StreamInput in) throws IOException { public EnvelopeBuilder readFrom(StreamInput in) throws IOException {
return new EnvelopeBuilder() return new EnvelopeBuilder(readCoordinateFrom(in), readCoordinateFrom(in));
.topLeft(readCoordinateFrom(in))
.bottomRight(readCoordinateFrom(in));
} }
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.common.geo.builders; package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.Shape;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.geo.XShapeCollection; import org.elasticsearch.common.geo.XShapeCollection;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
@ -35,7 +36,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.GEOMETRYCOLLECTION; public static final GeoShapeType TYPE = GeoShapeType.GEOMETRYCOLLECTION;
public static final GeometryCollectionBuilder PROTOTYPE = new GeometryCollectionBuilder(); static final GeometryCollectionBuilder PROTOTYPE = new GeometryCollectionBuilder();
protected final ArrayList<ShapeBuilder> shapes = new ArrayList<>(); protected final ArrayList<ShapeBuilder> shapes = new ArrayList<>();

View File

@ -24,6 +24,7 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -31,13 +32,32 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class LineStringBuilder extends PointCollection<LineStringBuilder> { public class LineStringBuilder extends CoordinateCollection<LineStringBuilder> {
/**
* Construct a new LineString.
* Per GeoJSON spec (http://geojson.org/geojson-spec.html#linestring)
* a LineString must contain two or more coordinates
* @param coordinates the initial list of coordinates
* @throws IllegalArgumentException if there are less then two coordinates defined
*/
public LineStringBuilder(List<Coordinate> coordinates) {
super(coordinates);
if (coordinates.size() < 2) {
throw new IllegalArgumentException("invalid number of points in LineString (found [" + coordinates.size()+ "] - must be >= 2)");
}
}
public LineStringBuilder(CoordinatesBuilder coordinates) {
this(coordinates.build());
}
public static final GeoShapeType TYPE = GeoShapeType.LINESTRING; public static final GeoShapeType TYPE = GeoShapeType.LINESTRING;
public static final LineStringBuilder PROTOTYPE = new LineStringBuilder(); static final LineStringBuilder PROTOTYPE = new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0).coordinate(1.0, 1.0));
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
@ -50,13 +70,14 @@ public class LineStringBuilder extends PointCollection<LineStringBuilder> {
} }
/** /**
* Closes the current lineString by adding the starting point as the end point * Closes the current lineString by adding the starting point as the end point.
* This will have no effect if starting and end point are already the same.
*/ */
public LineStringBuilder close() { public LineStringBuilder close() {
Coordinate start = points.get(0); Coordinate start = coordinates.get(0);
Coordinate end = points.get(points.size()-1); Coordinate end = coordinates.get(coordinates.size() - 1);
if(start.x != end.x || start.y != end.y) { if(start.x != end.x || start.y != end.y) {
points.add(start); coordinates.add(start);
} }
return this; return this;
} }
@ -68,7 +89,7 @@ public class LineStringBuilder extends PointCollection<LineStringBuilder> {
@Override @Override
public Shape build() { public Shape build() {
Coordinate[] coordinates = points.toArray(new Coordinate[points.size()]); Coordinate[] coordinates = this.coordinates.toArray(new Coordinate[this.coordinates.size()]);
Geometry geometry; Geometry geometry;
if(wrapdateline) { if(wrapdateline) {
ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>()); ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>());
@ -147,7 +168,7 @@ public class LineStringBuilder extends PointCollection<LineStringBuilder> {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(points); return Objects.hash(coordinates);
} }
@Override @Override
@ -159,24 +180,25 @@ public class LineStringBuilder extends PointCollection<LineStringBuilder> {
return false; return false;
} }
LineStringBuilder other = (LineStringBuilder) obj; LineStringBuilder other = (LineStringBuilder) obj;
return Objects.equals(points, other.points); return Objects.equals(coordinates, other.coordinates);
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(points.size()); out.writeVInt(coordinates.size());
for (Coordinate point : points) { for (Coordinate point : coordinates) {
writeCoordinateTo(point, out); writeCoordinateTo(point, out);
} }
} }
@Override @Override
public LineStringBuilder readFrom(StreamInput in) throws IOException { public LineStringBuilder readFrom(StreamInput in) throws IOException {
LineStringBuilder lineStringBuilder = new LineStringBuilder(); CoordinatesBuilder coordinates = new CoordinatesBuilder();
int size = in.readVInt(); int size = in.readVInt();
for (int i=0; i < size; i++) { for (int i=0; i < size; i++) {
lineStringBuilder.point(readCoordinateFrom(in)); coordinates.coordinate(readCoordinateFrom(in));
} }
LineStringBuilder lineStringBuilder = new LineStringBuilder(coordinates);
return lineStringBuilder; return lineStringBuilder;
} }
} }

View File

@ -23,6 +23,7 @@ import com.spatial4j.core.shape.Shape;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -36,7 +37,7 @@ public class MultiLineStringBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.MULTILINESTRING; public static final GeoShapeType TYPE = GeoShapeType.MULTILINESTRING;
public static final MultiLineStringBuilder PROTOTYPE = new MultiLineStringBuilder(); static final MultiLineStringBuilder PROTOTYPE = new MultiLineStringBuilder();
private final ArrayList<LineStringBuilder> lines = new ArrayList<>(); private final ArrayList<LineStringBuilder> lines = new ArrayList<>();
@ -45,10 +46,6 @@ public class MultiLineStringBuilder extends ShapeBuilder {
return this; return this;
} }
public MultiLineStringBuilder linestring(Coordinate[] coordinates) {
return this.linestring(new LineStringBuilder().points(coordinates));
}
public Coordinate[][] coordinates() { public Coordinate[][] coordinates() {
Coordinate[][] result = new Coordinate[lines.size()][]; Coordinate[][] result = new Coordinate[lines.size()][];
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {

View File

@ -22,6 +22,7 @@ package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Point; import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.Shape;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.geo.XShapeCollection; import org.elasticsearch.common.geo.XShapeCollection;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
@ -32,11 +33,19 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class MultiPointBuilder extends PointCollection<MultiPointBuilder> { public class MultiPointBuilder extends CoordinateCollection<MultiPointBuilder> {
public static final GeoShapeType TYPE = GeoShapeType.MULTIPOINT; public static final GeoShapeType TYPE = GeoShapeType.MULTIPOINT;
public final static MultiPointBuilder PROTOTYPE = new MultiPointBuilder(); final static MultiPointBuilder PROTOTYPE = new MultiPointBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0).build());
/**
* Create a new {@link MultiPointBuilder}.
* @param coordinates needs at least two coordinates to be valid, otherwise will throw an exception
*/
public MultiPointBuilder(List<Coordinate> coordinates) {
super(coordinates);
}
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
@ -52,8 +61,8 @@ public class MultiPointBuilder extends PointCollection<MultiPointBuilder> {
public Shape build() { public Shape build() {
//Could wrap JtsGeometry but probably slower due to conversions to/from JTS in relate() //Could wrap JtsGeometry but probably slower due to conversions to/from JTS in relate()
//MultiPoint geometry = FACTORY.createMultiPoint(points.toArray(new Coordinate[points.size()])); //MultiPoint geometry = FACTORY.createMultiPoint(points.toArray(new Coordinate[points.size()]));
List<Point> shapes = new ArrayList<>(points.size()); List<Point> shapes = new ArrayList<>(coordinates.size());
for (Coordinate coord : points) { for (Coordinate coord : coordinates) {
shapes.add(SPATIAL_CONTEXT.makePoint(coord.x, coord.y)); shapes.add(SPATIAL_CONTEXT.makePoint(coord.x, coord.y));
} }
XShapeCollection<Point> multiPoints = new XShapeCollection<>(shapes, SPATIAL_CONTEXT); XShapeCollection<Point> multiPoints = new XShapeCollection<>(shapes, SPATIAL_CONTEXT);
@ -68,7 +77,7 @@ public class MultiPointBuilder extends PointCollection<MultiPointBuilder> {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(points); return Objects.hash(coordinates);
} }
@Override @Override
@ -80,24 +89,26 @@ public class MultiPointBuilder extends PointCollection<MultiPointBuilder> {
return false; return false;
} }
MultiPointBuilder other = (MultiPointBuilder) obj; MultiPointBuilder other = (MultiPointBuilder) obj;
return Objects.equals(points, other.points); return Objects.equals(coordinates, other.coordinates);
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(points.size()); out.writeVInt(coordinates.size());
for (Coordinate point : points) { for (Coordinate point : coordinates) {
writeCoordinateTo(point, out); writeCoordinateTo(point, out);
} }
} }
@Override @Override
public MultiPointBuilder readFrom(StreamInput in) throws IOException { public MultiPointBuilder readFrom(StreamInput in) throws IOException {
MultiPointBuilder multiPointBuilder = new MultiPointBuilder();
int size = in.readVInt(); int size = in.readVInt();
List<Coordinate> points = new ArrayList<Coordinate>(size);
for (int i=0; i < size; i++) { for (int i=0; i < size; i++) {
multiPointBuilder.point(readCoordinateFrom(in)); points.add(readCoordinateFrom(in));
} }
MultiPointBuilder multiPointBuilder = new MultiPointBuilder(points);
return multiPointBuilder; return multiPointBuilder;
} }
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.Shape;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.geo.XShapeCollection; import org.elasticsearch.common.geo.XShapeCollection;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
@ -35,7 +36,7 @@ import java.util.Objects;
public class MultiPolygonBuilder extends ShapeBuilder { public class MultiPolygonBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.MULTIPOLYGON; public static final GeoShapeType TYPE = GeoShapeType.MULTIPOLYGON;
public static final MultiPolygonBuilder PROTOTYPE = new MultiPolygonBuilder(); static final MultiPolygonBuilder PROTOTYPE = new MultiPolygonBuilder();
private final ArrayList<PolygonBuilder> polygons = new ArrayList<>(); private final ArrayList<PolygonBuilder> polygons = new ArrayList<>();
@ -58,8 +59,7 @@ public class MultiPolygonBuilder extends ShapeBuilder {
* {@link MultiPolygonBuilder} to the polygon if polygon has different orientation. * {@link MultiPolygonBuilder} to the polygon if polygon has different orientation.
*/ */
public MultiPolygonBuilder polygon(PolygonBuilder polygon) { public MultiPolygonBuilder polygon(PolygonBuilder polygon) {
PolygonBuilder pb = new PolygonBuilder(this.orientation); PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinates(polygon.shell().coordinates(false)), this.orientation);
pb.points(polygon.shell().coordinates(false));
for (LineStringBuilder hole : polygon.holes()) { for (LineStringBuilder hole : polygon.holes()) {
pb.hole(hole); pb.hole(hole);
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.geo.builders;
import com.spatial4j.core.shape.Point; import com.spatial4j.core.shape.Point;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -31,10 +32,17 @@ import java.util.Objects;
public class PointBuilder extends ShapeBuilder { public class PointBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.POINT; public static final GeoShapeType TYPE = GeoShapeType.POINT;
public static final PointBuilder PROTOTYPE = new PointBuilder(); static final PointBuilder PROTOTYPE = new PointBuilder();
private Coordinate coordinate; private Coordinate coordinate;
/**
* Create a point at [0.0,0.0]
*/
public PointBuilder() {
this.coordinate = ZERO_ZERO;
}
public PointBuilder coordinate(Coordinate coordinate) { public PointBuilder coordinate(Coordinate coordinate) {
this.coordinate = coordinate; this.coordinate = coordinate;
return this; return this;

View File

@ -27,6 +27,7 @@ import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.MultiPolygon; import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
@ -52,7 +53,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class PolygonBuilder extends ShapeBuilder { public class PolygonBuilder extends ShapeBuilder {
public static final GeoShapeType TYPE = GeoShapeType.POLYGON; public static final GeoShapeType TYPE = GeoShapeType.POLYGON;
public static final PolygonBuilder PROTOTYPE = new PolygonBuilder(); static final PolygonBuilder PROTOTYPE = new PolygonBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0).coordinate(0.0, 1.0)
.coordinate(1.0, 0.0).coordinate(0.0, 0.0));
private static final Coordinate[][] EMPTY = new Coordinate[0][]; private static final Coordinate[][] EMPTY = new Coordinate[0][];
@ -64,54 +66,51 @@ public class PolygonBuilder extends ShapeBuilder {
// List of line strings defining the holes of the polygon // List of line strings defining the holes of the polygon
private final ArrayList<LineStringBuilder> holes = new ArrayList<>(); private final ArrayList<LineStringBuilder> holes = new ArrayList<>();
public PolygonBuilder() { public PolygonBuilder(LineStringBuilder lineString, Orientation orientation, boolean coerce) {
this(Orientation.RIGHT);
}
public PolygonBuilder(Orientation orientation) {
this(new ArrayList<Coordinate>(), orientation);
}
public PolygonBuilder(ArrayList<Coordinate> points, Orientation orientation) {
this.orientation = orientation; this.orientation = orientation;
this.shell = new LineStringBuilder().points(points); if (coerce) {
lineString.close();
}
validateLinearRing(lineString);
this.shell = lineString;
}
public PolygonBuilder(LineStringBuilder lineString, Orientation orientation) {
this(lineString, orientation, false);
}
public PolygonBuilder(CoordinatesBuilder coordinates, Orientation orientation) {
this(new LineStringBuilder(coordinates), orientation, false);
}
public PolygonBuilder(CoordinatesBuilder coordinates) {
this(coordinates, Orientation.RIGHT);
} }
public Orientation orientation() { public Orientation orientation() {
return this.orientation; return this.orientation;
} }
public PolygonBuilder point(double longitude, double latitude) {
shell.point(longitude, latitude);
return this;
}
/**
* Add a point to the shell of the polygon
* @param coordinate coordinate of the new point
* @return this
*/
public PolygonBuilder point(Coordinate coordinate) {
shell.point(coordinate);
return this;
}
/**
* Add an array of points to the shell of the polygon
* @param coordinates coordinates of the new points to add
* @return this
*/
public PolygonBuilder points(Coordinate...coordinates) {
shell.points(coordinates);
return this;
}
/** /**
* Add a new hole to the polygon * Add a new hole to the polygon
* @param hole linear ring defining the hole * @param hole linear ring defining the hole
* @return this * @return this
*/ */
public PolygonBuilder hole(LineStringBuilder hole) { public PolygonBuilder hole(LineStringBuilder hole) {
return this.hole(hole, false);
}
/**
* Add a new hole to the polygon
* @param hole linear ring defining the hole
* @param coerce if set to true, it will try to close the hole by adding starting point as end point
* @return this
*/
public PolygonBuilder hole(LineStringBuilder hole, boolean coerce) {
if (coerce) {
hole.close();
}
validateLinearRing(hole);
holes.add(hole); holes.add(hole);
return this; return this;
} }
@ -138,12 +137,30 @@ public class PolygonBuilder extends ShapeBuilder {
return this; return this;
} }
private static void validateLinearRing(LineStringBuilder lineString) {
/**
* Per GeoJSON spec (http://geojson.org/geojson-spec.html#linestring)
* A LinearRing is closed LineString with 4 or more positions. The first and last positions
* are equivalent (they represent equivalent points). Though a LinearRing is not explicitly
* represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.
*/
List<Coordinate> points = lineString.coordinates;
if (points.size() < 4) {
throw new IllegalArgumentException(
"invalid number of points in LinearRing (found [" + points.size() + "] - must be >= 4)");
}
if (!points.get(0).equals(points.get(points.size() - 1))) {
throw new IllegalArgumentException("invalid LinearRing found (coordinates are not closed)");
}
}
/** /**
* Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon * Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon
*/ */
protected void validateHole(LineStringBuilder shell, LineStringBuilder hole) { protected void validateHole(LineStringBuilder shell, LineStringBuilder hole) {
HashSet<Coordinate> exterior = Sets.newHashSet(shell.points); HashSet<Coordinate> exterior = Sets.newHashSet(shell.coordinates);
HashSet<Coordinate> interior = Sets.newHashSet(hole.points); HashSet<Coordinate> interior = Sets.newHashSet(hole.coordinates);
exterior.retainAll(interior); exterior.retainAll(interior);
if (exterior.size() >= 2) { if (exterior.size() >= 2) {
throw new InvalidShapeException("Invalid polygon, interior cannot share more than one point with the exterior"); throw new InvalidShapeException("Invalid polygon, interior cannot share more than one point with the exterior");
@ -161,9 +178,9 @@ public class PolygonBuilder extends ShapeBuilder {
* @return coordinates of the polygon * @return coordinates of the polygon
*/ */
public Coordinate[][][] coordinates() { public Coordinate[][][] coordinates() {
int numEdges = shell.points.size()-1; // Last point is repeated int numEdges = shell.coordinates.size()-1; // Last point is repeated
for (int i = 0; i < holes.size(); i++) { for (int i = 0; i < holes.size(); i++) {
numEdges += holes.get(i).points.size()-1; numEdges += holes.get(i).coordinates.size()-1;
validateHole(shell, this.holes.get(i)); validateHole(shell, this.holes.get(i));
} }
@ -226,16 +243,16 @@ public class PolygonBuilder extends ShapeBuilder {
} }
protected Polygon toPolygon(GeometryFactory factory) { protected Polygon toPolygon(GeometryFactory factory) {
final LinearRing shell = linearRing(factory, this.shell.points); final LinearRing shell = linearRing(factory, this.shell.coordinates);
final LinearRing[] holes = new LinearRing[this.holes.size()]; final LinearRing[] holes = new LinearRing[this.holes.size()];
Iterator<LineStringBuilder> iterator = this.holes.iterator(); Iterator<LineStringBuilder> iterator = this.holes.iterator();
for (int i = 0; iterator.hasNext(); i++) { for (int i = 0; iterator.hasNext(); i++) {
holes[i] = linearRing(factory, iterator.next().points); holes[i] = linearRing(factory, iterator.next().coordinates);
} }
return factory.createPolygon(shell, holes); return factory.createPolygon(shell, holes);
} }
protected static LinearRing linearRing(GeometryFactory factory, ArrayList<Coordinate> coordinates) { protected static LinearRing linearRing(GeometryFactory factory, List<Coordinate> coordinates) {
return factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()])); return factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()]));
} }
@ -711,8 +728,8 @@ public class PolygonBuilder extends ShapeBuilder {
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
orientation.writeTo(out);
shell.writeTo(out); shell.writeTo(out);
orientation.writeTo(out);
out.writeVInt(holes.size()); out.writeVInt(holes.size());
for (LineStringBuilder hole : holes) { for (LineStringBuilder hole : holes) {
hole.writeTo(out); hole.writeTo(out);
@ -721,8 +738,9 @@ public class PolygonBuilder extends ShapeBuilder {
@Override @Override
public PolygonBuilder readFrom(StreamInput in) throws IOException { public PolygonBuilder readFrom(StreamInput in) throws IOException {
PolygonBuilder polyBuilder = new PolygonBuilder(Orientation.readFrom(in)); LineStringBuilder shell = LineStringBuilder.PROTOTYPE.readFrom(in);
polyBuilder.shell = LineStringBuilder.PROTOTYPE.readFrom(in); Orientation orientation = Orientation.readFrom(in);
PolygonBuilder polyBuilder = new PolygonBuilder(shell, orientation);
int holes = in.readVInt(); int holes = in.readVInt();
for (int i = 0; i < holes; i++) { for (int i = 0; i < holes; i++) {
polyBuilder.hole(LineStringBuilder.PROTOTYPE.readFrom(in)); polyBuilder.hole(LineStringBuilder.PROTOTYPE.readFrom(in));

View File

@ -26,6 +26,7 @@ import com.spatial4j.core.shape.jts.JtsGeometry;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.support.ToXContentToBytes; import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.NamedWriteable;
@ -64,6 +65,11 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
} }
public static final double DATELINE = 180; public static final double DATELINE = 180;
/**
* coordinate at [0.0, 0.0]
*/
public static final Coordinate ZERO_ZERO = new Coordinate(0.0, 0.0);
// TODO how might we use JtsSpatialContextFactory to configure the context (esp. for non-geo)? // TODO how might we use JtsSpatialContextFactory to configure the context (esp. for non-geo)?
public static final JtsSpatialContext SPATIAL_CONTEXT = JtsSpatialContext.GEO; public static final JtsSpatialContext SPATIAL_CONTEXT = JtsSpatialContext.GEO;
public static final GeometryFactory FACTORY = SPATIAL_CONTEXT.getGeometryFactory(); public static final GeometryFactory FACTORY = SPATIAL_CONTEXT.getGeometryFactory();
@ -81,11 +87,6 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
protected final boolean autoIndexJtsGeometry = true;//may want to turn off once SpatialStrategy impls do it. protected final boolean autoIndexJtsGeometry = true;//may want to turn off once SpatialStrategy impls do it.
protected ShapeBuilder() { protected ShapeBuilder() {
}
protected static Coordinate coordinate(double longitude, double latitude) {
return new Coordinate(longitude, latitude);
} }
protected JtsGeometry jtsGeometry(Geometry geom) { protected JtsGeometry jtsGeometry(Geometry geom) {
@ -569,7 +570,7 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
uL = new Coordinate(Math.min(uL.x, lR.x), Math.max(uL.y, lR.y)); uL = new Coordinate(Math.min(uL.x, lR.x), Math.max(uL.y, lR.y));
lR = new Coordinate(Math.max(uLtmp.x, lR.x), Math.min(uLtmp.y, lR.y)); lR = new Coordinate(Math.max(uLtmp.x, lR.x), Math.min(uLtmp.y, lR.y));
} }
return ShapeBuilders.newEnvelope().topLeft(uL).bottomRight(lR); return ShapeBuilders.newEnvelope(uL, lR);
} }
protected static void validateMultiPointNode(CoordinateNode coordinates) { protected static void validateMultiPointNode(CoordinateNode coordinates) {
@ -589,12 +590,11 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
protected static MultiPointBuilder parseMultiPoint(CoordinateNode coordinates) { protected static MultiPointBuilder parseMultiPoint(CoordinateNode coordinates) {
validateMultiPointNode(coordinates); validateMultiPointNode(coordinates);
CoordinatesBuilder points = new CoordinatesBuilder();
MultiPointBuilder points = new MultiPointBuilder();
for (CoordinateNode node : coordinates.children) { for (CoordinateNode node : coordinates.children) {
points.point(node.coordinate); points.coordinate(node.coordinate);
} }
return points; return new MultiPointBuilder(points.build());
} }
protected static LineStringBuilder parseLineString(CoordinateNode coordinates) { protected static LineStringBuilder parseLineString(CoordinateNode coordinates) {
@ -607,11 +607,11 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
throw new ElasticsearchParseException("invalid number of points in LineString (found [{}] - must be >= 2)", coordinates.children.size()); throw new ElasticsearchParseException("invalid number of points in LineString (found [{}] - must be >= 2)", coordinates.children.size());
} }
LineStringBuilder line = ShapeBuilders.newLineString(); CoordinatesBuilder line = new CoordinatesBuilder();
for (CoordinateNode node : coordinates.children) { for (CoordinateNode node : coordinates.children) {
line.point(node.coordinate); line.coordinate(node.coordinate);
} }
return line; return ShapeBuilders.newLineString(line);
} }
protected static MultiLineStringBuilder parseMultiLine(CoordinateNode coordinates) { protected static MultiLineStringBuilder parseMultiLine(CoordinateNode coordinates) {
@ -659,7 +659,7 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
} }
LineStringBuilder shell = parseLinearRing(coordinates.children.get(0), coerce); LineStringBuilder shell = parseLinearRing(coordinates.children.get(0), coerce);
PolygonBuilder polygon = new PolygonBuilder(shell.points, orientation); PolygonBuilder polygon = new PolygonBuilder(shell, orientation);
for (int i = 1; i < coordinates.children.size(); i++) { for (int i = 1; i < coordinates.children.size(); i++) {
polygon.hole(parseLinearRing(coordinates.children.get(i), coerce)); polygon.hole(parseLinearRing(coordinates.children.get(i), coerce));
} }

View File

@ -21,6 +21,8 @@ package org.elasticsearch.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import java.util.List;
/** /**
* A collection of static methods for creating ShapeBuilders. * A collection of static methods for creating ShapeBuilders.
*/ */
@ -50,16 +52,24 @@ public class ShapeBuilders {
* Create a new set of points * Create a new set of points
* @return new {@link MultiPointBuilder} * @return new {@link MultiPointBuilder}
*/ */
public static MultiPointBuilder newMultiPoint() { public static MultiPointBuilder newMultiPoint(List<Coordinate> points) {
return new MultiPointBuilder(); return new MultiPointBuilder(points);
} }
/** /**
* Create a new lineString * Create a new lineString
* @return a new {@link LineStringBuilder} * @return a new {@link LineStringBuilder}
*/ */
public static LineStringBuilder newLineString() { public static LineStringBuilder newLineString(List<Coordinate> list) {
return new LineStringBuilder(); return new LineStringBuilder(list);
}
/**
* Create a new lineString
* @return a new {@link LineStringBuilder}
*/
public static LineStringBuilder newLineString(CoordinatesBuilder coordinates) {
return new LineStringBuilder(coordinates);
} }
/** /**
@ -71,19 +81,19 @@ public class ShapeBuilders {
} }
/** /**
* Create a new Polygon * Create a new PolygonBuilder
* @return a new {@link PointBuilder} * @return a new {@link PolygonBuilder}
*/ */
public static PolygonBuilder newPolygon() { public static PolygonBuilder newPolygon(List<Coordinate> shell) {
return new PolygonBuilder(); return new PolygonBuilder(new CoordinatesBuilder().coordinates(shell));
} }
/** /**
* Create a new Polygon * Create a new PolygonBuilder
* @return a new {@link PointBuilder} * @return a new {@link PolygonBuilder}
*/ */
public static PolygonBuilder newPolygon(ShapeBuilder.Orientation orientation) { public static PolygonBuilder newPolygon(CoordinatesBuilder shell) {
return new PolygonBuilder(orientation); return new PolygonBuilder(shell);
} }
/** /**
@ -124,7 +134,7 @@ public class ShapeBuilders {
* *
* @return a new {@link EnvelopeBuilder} * @return a new {@link EnvelopeBuilder}
*/ */
public static EnvelopeBuilder newEnvelope() { public static EnvelopeBuilder newEnvelope(Coordinate topLeft, Coordinate bottomRight) {
return new EnvelopeBuilder(); return new EnvelopeBuilder(topLeft, bottomRight);
} }
} }

View File

@ -81,6 +81,4 @@ public final class ConfigurationException extends RuntimeException {
public String getMessage() { public String getMessage() {
return Errors.format("Guice configuration errors", messages); return Errors.format("Guice configuration errors", messages);
} }
private static final long serialVersionUID = 0;
} }

View File

@ -52,6 +52,4 @@ public class CreationException extends RuntimeException {
public String getMessage() { public String getMessage() {
return Errors.format("Guice creation errors", messages); return Errors.format("Guice creation errors", messages);
} }
private static final long serialVersionUID = 0;
} }

View File

@ -68,6 +68,4 @@ public final class ProvisionException extends RuntimeException {
public String getMessage() { public String getMessage() {
return Errors.format("Guice provision errors", messages); return Errors.format("Guice provision errors", messages);
} }
private static final long serialVersionUID = 0;
} }

View File

@ -32,7 +32,6 @@ import org.elasticsearch.common.inject.spi.Message;
import org.elasticsearch.common.inject.spi.TypeListenerBinding; import org.elasticsearch.common.inject.spi.TypeListenerBinding;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -66,7 +65,7 @@ import static java.util.Collections.unmodifiableList;
* *
* @author jessewilson@google.com (Jesse Wilson) * @author jessewilson@google.com (Jesse Wilson)
*/ */
public final class Errors implements Serializable { public final class Errors {
/** /**
* The root errors object. Used to access the list of error messages. * The root errors object. Used to access the list of error messages.

View File

@ -313,7 +313,5 @@ public final class Join {
private JoinException(IOException cause) { private JoinException(IOException cause) {
super(cause); super(cause);
} }
private static final long serialVersionUID = 1L;
} }
} }

View File

@ -21,7 +21,6 @@ import org.elasticsearch.common.inject.ConfigurationException;
import org.elasticsearch.common.inject.TypeLiteral; import org.elasticsearch.common.inject.TypeLiteral;
import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.inject.spi.Message;
import java.io.Serializable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericArrayType;
@ -108,8 +107,7 @@ public class MoreTypes {
/** /**
* Returns a type that is functionally equal but not necessarily equal * Returns a type that is functionally equal but not necessarily equal
* according to {@link Object#equals(Object) Object.equals()}. The returned * according to {@link Object#equals(Object) Object.equals()}.
* type is {@link Serializable}.
*/ */
public static Type canonicalize(Type type) { public static Type canonicalize(Type type) {
if (type instanceof ParameterizedTypeImpl if (type instanceof ParameterizedTypeImpl
@ -140,17 +138,6 @@ public class MoreTypes {
} }
} }
/**
* Returns a type that's functionally equal but not necessarily equal
* according to {@link Object#equals(Object) Object.equals}. The returned
* member is {@link Serializable}.
*/
public static Member serializableCopy(Member member) {
return member instanceof MemberImpl
? member
: new MemberImpl(member);
}
public static Class<?> getRawType(Type type) { public static Class<?> getRawType(Type type) {
if (type instanceof Class<?>) { if (type instanceof Class<?>) {
// type is a normal class. // type is a normal class.
@ -450,7 +437,7 @@ public class MoreTypes {
} }
public static class ParameterizedTypeImpl public static class ParameterizedTypeImpl
implements ParameterizedType, Serializable, CompositeType { implements ParameterizedType, CompositeType {
private final Type ownerType; private final Type ownerType;
private final Type rawType; private final Type rawType;
private final Type[] typeArguments; private final Type[] typeArguments;
@ -527,12 +514,10 @@ public class MoreTypes {
public String toString() { public String toString() {
return MoreTypes.toString(this); return MoreTypes.toString(this);
} }
private static final long serialVersionUID = 0;
} }
public static class GenericArrayTypeImpl public static class GenericArrayTypeImpl
implements GenericArrayType, Serializable, CompositeType { implements GenericArrayType, CompositeType {
private final Type componentType; private final Type componentType;
public GenericArrayTypeImpl(Type componentType) { public GenericArrayTypeImpl(Type componentType) {
@ -564,8 +549,6 @@ public class MoreTypes {
public String toString() { public String toString() {
return MoreTypes.toString(this); return MoreTypes.toString(this);
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -573,7 +556,7 @@ public class MoreTypes {
* lower bounds. We only support what the Java 6 language needs - at most one * lower bounds. We only support what the Java 6 language needs - at most one
* bound. If a lower bound is set, the upper bound must be Object.class. * bound. If a lower bound is set, the upper bound must be Object.class.
*/ */
public static class WildcardTypeImpl implements WildcardType, Serializable, CompositeType { public static class WildcardTypeImpl implements WildcardType, CompositeType {
private final Type upperBound; private final Type upperBound;
private final Type lowerBound; private final Type lowerBound;
@ -632,8 +615,6 @@ public class MoreTypes {
public String toString() { public String toString() {
return MoreTypes.toString(this); return MoreTypes.toString(this);
} }
private static final long serialVersionUID = 0;
} }
private static void checkNotPrimitive(Type type, String use) { private static void checkNotPrimitive(Type type, String use) {
@ -647,7 +628,7 @@ public class MoreTypes {
* our exception types. We workaround this with this serializable implementation. It includes all * our exception types. We workaround this with this serializable implementation. It includes all
* of the API methods, plus everything we use for line numbers and messaging. * of the API methods, plus everything we use for line numbers and messaging.
*/ */
public static class MemberImpl implements Member, Serializable { public static class MemberImpl implements Member {
private final Class<?> declaringClass; private final Class<?> declaringClass;
private final String name; private final String name;
private final int modifiers; private final int modifiers;

View File

@ -16,8 +16,6 @@
package org.elasticsearch.common.inject.matcher; package org.elasticsearch.common.inject.matcher;
import java.io.Serializable;
/** /**
* Implements {@code and()} and {@code or()}. * Implements {@code and()} and {@code or()}.
* *
@ -35,7 +33,7 @@ public abstract class AbstractMatcher<T> implements Matcher<T> {
return new OrMatcher<>(this, other); return new OrMatcher<>(this, other);
} }
private static class AndMatcher<T> extends AbstractMatcher<T> implements Serializable { private static class AndMatcher<T> extends AbstractMatcher<T> {
private final Matcher<? super T> a, b; private final Matcher<? super T> a, b;
public AndMatcher(Matcher<? super T> a, Matcher<? super T> b) { public AndMatcher(Matcher<? super T> a, Matcher<? super T> b) {
@ -64,11 +62,9 @@ public abstract class AbstractMatcher<T> implements Matcher<T> {
public String toString() { public String toString() {
return "and(" + a + ", " + b + ")"; return "and(" + a + ", " + b + ")";
} }
private static final long serialVersionUID = 0;
} }
private static class OrMatcher<T> extends AbstractMatcher<T> implements Serializable { private static class OrMatcher<T> extends AbstractMatcher<T> {
private final Matcher<? super T> a, b; private final Matcher<? super T> a, b;
public OrMatcher(Matcher<? super T> a, Matcher<? super T> b) { public OrMatcher(Matcher<? super T> a, Matcher<? super T> b) {
@ -97,7 +93,5 @@ public abstract class AbstractMatcher<T> implements Matcher<T> {
public String toString() { public String toString() {
return "or(" + a + ", " + b + ")"; return "or(" + a + ", " + b + ")";
} }
private static final long serialVersionUID = 0;
} }
} }

View File

@ -16,7 +16,6 @@
package org.elasticsearch.common.inject.matcher; package org.elasticsearch.common.inject.matcher;
import java.io.Serializable;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -42,7 +41,7 @@ public class Matchers {
private static final Matcher<Object> ANY = new Any(); private static final Matcher<Object> ANY = new Any();
private static class Any extends AbstractMatcher<Object> implements Serializable { private static class Any extends AbstractMatcher<Object> {
@Override @Override
public boolean matches(Object o) { public boolean matches(Object o) {
return true; return true;
@ -56,8 +55,6 @@ public class Matchers {
public Object readResolve() { public Object readResolve() {
return any(); return any();
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -67,7 +64,7 @@ public class Matchers {
return new Not<>(p); return new Not<>(p);
} }
private static class Not<T> extends AbstractMatcher<T> implements Serializable { private static class Not<T> extends AbstractMatcher<T> {
final Matcher<? super T> delegate; final Matcher<? super T> delegate;
private Not(Matcher<? super T> delegate) { private Not(Matcher<? super T> delegate) {
@ -94,8 +91,6 @@ public class Matchers {
public String toString() { public String toString() {
return "not(" + delegate + ")"; return "not(" + delegate + ")";
} }
private static final long serialVersionUID = 0;
} }
private static void checkForRuntimeRetention( private static void checkForRuntimeRetention(
@ -115,8 +110,7 @@ public class Matchers {
return new AnnotatedWithType(annotationType); return new AnnotatedWithType(annotationType);
} }
private static class AnnotatedWithType extends AbstractMatcher<AnnotatedElement> private static class AnnotatedWithType extends AbstractMatcher<AnnotatedElement> {
implements Serializable {
private final Class<? extends Annotation> annotationType; private final Class<? extends Annotation> annotationType;
public AnnotatedWithType(Class<? extends Annotation> annotationType) { public AnnotatedWithType(Class<? extends Annotation> annotationType) {
@ -144,8 +138,6 @@ public class Matchers {
public String toString() { public String toString() {
return "annotatedWith(" + annotationType.getSimpleName() + ".class)"; return "annotatedWith(" + annotationType.getSimpleName() + ".class)";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -157,8 +149,7 @@ public class Matchers {
return new AnnotatedWith(annotation); return new AnnotatedWith(annotation);
} }
private static class AnnotatedWith extends AbstractMatcher<AnnotatedElement> private static class AnnotatedWith extends AbstractMatcher<AnnotatedElement> {
implements Serializable {
private final Annotation annotation; private final Annotation annotation;
public AnnotatedWith(Annotation annotation) { public AnnotatedWith(Annotation annotation) {
@ -187,8 +178,6 @@ public class Matchers {
public String toString() { public String toString() {
return "annotatedWith(" + annotation + ")"; return "annotatedWith(" + annotation + ")";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -199,8 +188,7 @@ public class Matchers {
return new SubclassesOf(superclass); return new SubclassesOf(superclass);
} }
private static class SubclassesOf extends AbstractMatcher<Class> private static class SubclassesOf extends AbstractMatcher<Class> {
implements Serializable {
private final Class<?> superclass; private final Class<?> superclass;
public SubclassesOf(Class<?> superclass) { public SubclassesOf(Class<?> superclass) {
@ -227,8 +215,6 @@ public class Matchers {
public String toString() { public String toString() {
return "subclassesOf(" + superclass.getSimpleName() + ".class)"; return "subclassesOf(" + superclass.getSimpleName() + ".class)";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -238,8 +224,7 @@ public class Matchers {
return new Only(value); return new Only(value);
} }
private static class Only extends AbstractMatcher<Object> private static class Only extends AbstractMatcher<Object> {
implements Serializable {
private final Object value; private final Object value;
public Only(Object value) { public Only(Object value) {
@ -266,8 +251,6 @@ public class Matchers {
public String toString() { public String toString() {
return "only(" + value + ")"; return "only(" + value + ")";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -277,8 +260,7 @@ public class Matchers {
return new IdenticalTo(value); return new IdenticalTo(value);
} }
private static class IdenticalTo extends AbstractMatcher<Object> private static class IdenticalTo extends AbstractMatcher<Object> {
implements Serializable {
private final Object value; private final Object value;
public IdenticalTo(Object value) { public IdenticalTo(Object value) {
@ -305,8 +287,6 @@ public class Matchers {
public String toString() { public String toString() {
return "identicalTo(" + value + ")"; return "identicalTo(" + value + ")";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -317,7 +297,7 @@ public class Matchers {
return new InPackage(targetPackage); return new InPackage(targetPackage);
} }
private static class InPackage extends AbstractMatcher<Class> implements Serializable { private static class InPackage extends AbstractMatcher<Class> {
private final transient Package targetPackage; private final transient Package targetPackage;
private final String packageName; private final String packageName;
@ -350,8 +330,6 @@ public class Matchers {
public Object readResolve() { public Object readResolve() {
return inPackage(Package.getPackage(packageName)); return inPackage(Package.getPackage(packageName));
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -364,7 +342,7 @@ public class Matchers {
return new InSubpackage(targetPackageName); return new InSubpackage(targetPackageName);
} }
private static class InSubpackage extends AbstractMatcher<Class> implements Serializable { private static class InSubpackage extends AbstractMatcher<Class> {
private final String targetPackageName; private final String targetPackageName;
public InSubpackage(String targetPackageName) { public InSubpackage(String targetPackageName) {
@ -393,8 +371,6 @@ public class Matchers {
public String toString() { public String toString() {
return "inSubpackage(" + targetPackageName + ")"; return "inSubpackage(" + targetPackageName + ")";
} }
private static final long serialVersionUID = 0;
} }
/** /**
@ -405,7 +381,7 @@ public class Matchers {
return new Returns(returnType); return new Returns(returnType);
} }
private static class Returns extends AbstractMatcher<Method> implements Serializable { private static class Returns extends AbstractMatcher<Method> {
private final Matcher<? super Class<?>> returnType; private final Matcher<? super Class<?>> returnType;
public Returns(Matcher<? super Class<?>> returnType) { public Returns(Matcher<? super Class<?>> returnType) {
@ -432,7 +408,5 @@ public class Matchers {
public String toString() { public String toString() {
return "returns(" + returnType + ")"; return "returns(" + returnType + ")";
} }
private static final long serialVersionUID = 0;
} }
} }

View File

@ -16,11 +16,10 @@
package org.elasticsearch.common.inject.name; package org.elasticsearch.common.inject.name;
import java.io.Serializable;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Objects; import java.util.Objects;
class NamedImpl implements Named, Serializable { class NamedImpl implements Named {
private final String value; private final String value;
@ -58,6 +57,4 @@ class NamedImpl implements Named, Serializable {
public Class<? extends Annotation> annotationType() { public Class<? extends Annotation> annotationType() {
return Named.class; return Named.class;
} }
private static final long serialVersionUID = 0;
} }

View File

@ -20,9 +20,6 @@ import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.internal.SourceProvider; import org.elasticsearch.common.inject.internal.SourceProvider;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -40,7 +37,7 @@ import java.util.Objects;
* *
* @author crazybob@google.com (Bob Lee) * @author crazybob@google.com (Bob Lee)
*/ */
public final class Message implements Serializable, Element { public final class Message implements Element {
private final String message; private final String message;
private final Throwable cause; private final Throwable cause;
private final List<Object> sources; private final List<Object> sources;
@ -131,18 +128,4 @@ public final class Message implements Serializable, Element {
public void applyTo(Binder binder) { public void applyTo(Binder binder) {
binder.withSource(getSource()).addError(this); binder.withSource(getSource()).addError(this);
} }
/**
* When serialized, we eagerly convert sources to strings. This hurts our formatting, but it
* guarantees that the receiving end will be able to read the message.
*/
private Object writeReplace() throws ObjectStreamException {
Object[] sourcesAsStrings = sources.toArray();
for (int i = 0; i < sourcesAsStrings.length; i++) {
sourcesAsStrings[i] = Errors.convert(sourcesAsStrings[i]).toString();
}
return new Message(Arrays.asList(sourcesAsStrings), message, cause);
}
private static final long serialVersionUID = 0;
} }

View File

@ -45,7 +45,7 @@ public final class Types {
* Returns a new parameterized type, applying {@code typeArguments} to * Returns a new parameterized type, applying {@code typeArguments} to
* {@code rawType}. The returned type does not have an owner type. * {@code rawType}. The returned type does not have an owner type.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments) { public static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments) {
return newParameterizedTypeWithOwner(null, rawType, typeArguments); return newParameterizedTypeWithOwner(null, rawType, typeArguments);
@ -55,7 +55,7 @@ public final class Types {
* Returns a new parameterized type, applying {@code typeArguments} to * Returns a new parameterized type, applying {@code typeArguments} to
* {@code rawType} and enclosed by {@code ownerType}. * {@code rawType} and enclosed by {@code ownerType}.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType newParameterizedTypeWithOwner( public static ParameterizedType newParameterizedTypeWithOwner(
Type ownerType, Type rawType, Type... typeArguments) { Type ownerType, Type rawType, Type... typeArguments) {
@ -66,7 +66,7 @@ public final class Types {
* Returns an array type whose elements are all instances of * Returns an array type whose elements are all instances of
* {@code componentType}. * {@code componentType}.
* *
* @return a {@link java.io.Serializable serializable} generic array type. * @return a generic array type.
*/ */
public static GenericArrayType arrayOf(Type componentType) { public static GenericArrayType arrayOf(Type componentType) {
return new GenericArrayTypeImpl(componentType); return new GenericArrayTypeImpl(componentType);
@ -95,7 +95,7 @@ public final class Types {
* Returns a type modelling a {@link List} whose elements are of type * Returns a type modelling a {@link List} whose elements are of type
* {@code elementType}. * {@code elementType}.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType listOf(Type elementType) { public static ParameterizedType listOf(Type elementType) {
return newParameterizedType(List.class, elementType); return newParameterizedType(List.class, elementType);
@ -105,7 +105,7 @@ public final class Types {
* Returns a type modelling a {@link Set} whose elements are of type * Returns a type modelling a {@link Set} whose elements are of type
* {@code elementType}. * {@code elementType}.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType setOf(Type elementType) { public static ParameterizedType setOf(Type elementType) {
return newParameterizedType(Set.class, elementType); return newParameterizedType(Set.class, elementType);
@ -115,7 +115,7 @@ public final class Types {
* Returns a type modelling a {@link Map} whose keys are of type * Returns a type modelling a {@link Map} whose keys are of type
* {@code keyType} and whose values are of type {@code valueType}. * {@code keyType} and whose values are of type {@code valueType}.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType mapOf(Type keyType, Type valueType) { public static ParameterizedType mapOf(Type keyType, Type valueType) {
return newParameterizedType(Map.class, keyType, valueType); return newParameterizedType(Map.class, keyType, valueType);
@ -127,7 +127,7 @@ public final class Types {
* Returns a type modelling a {@link Provider} that provides elements of type * Returns a type modelling a {@link Provider} that provides elements of type
* {@code elementType}. * {@code elementType}.
* *
* @return a {@link java.io.Serializable serializable} parameterized type. * @return a parameterized type.
*/ */
public static ParameterizedType providerOf(Type providedType) { public static ParameterizedType providerOf(Type providedType) {
return newParameterizedType(Provider.class, providedType); return newParameterizedType(Provider.class, providedType);

View File

@ -296,8 +296,6 @@ public class Joda {
public static final DurationFieldType Quarters = new DurationFieldType("quarters") { public static final DurationFieldType Quarters = new DurationFieldType("quarters") {
private static final long serialVersionUID = -8167713675442491871L;
@Override @Override
public DurationField getField(Chronology chronology) { public DurationField getField(Chronology chronology) {
return new ScaledDurationField(chronology.months(), Quarters, 3); return new ScaledDurationField(chronology.months(), Quarters, 3);
@ -305,8 +303,6 @@ public class Joda {
}; };
public static final DateTimeFieldType QuarterOfYear = new DateTimeFieldType("quarterOfYear") { public static final DateTimeFieldType QuarterOfYear = new DateTimeFieldType("quarterOfYear") {
private static final long serialVersionUID = -5677872459807379123L;
@Override @Override
public DurationFieldType getDurationType() { public DurationFieldType getDurationType() {
return Quarters; return Quarters;

View File

@ -30,8 +30,6 @@ import java.util.logging.LogRecord;
* information of the code calling the logger * information of the code calling the logger
*/ */
public class ESLogRecord extends LogRecord { public class ESLogRecord extends LogRecord {
private static final long serialVersionUID = 1107741560233585726L;
private static final String FQCN = AbstractESLogger.class.getName(); private static final String FQCN = AbstractESLogger.class.getName();
private String sourceClassName; private String sourceClassName;
private String sourceMethodName; private String sourceMethodName;

View File

@ -656,7 +656,7 @@ public final class XMoreLikeThis {
} }
} }
// term selection is per field, then appended to a single boolean query // term selection is per field, then appended to a single boolean query
BooleanQuery bq = new BooleanQuery(); BooleanQuery.Builder bq = new BooleanQuery.Builder();
for (String fieldName : fieldNames) { for (String fieldName : fieldNames) {
Map<String, Int> termFreqMap = new HashMap<>(); Map<String, Int> termFreqMap = new HashMap<>();
for (Fields fields : likeFields) { for (Fields fields : likeFields) {
@ -667,22 +667,22 @@ public final class XMoreLikeThis {
} }
addToQuery(createQueue(termFreqMap, fieldName), bq); addToQuery(createQueue(termFreqMap, fieldName), bq);
} }
return bq; return bq.build();
} }
/** /**
* Create the More like query from a PriorityQueue * Create the More like query from a PriorityQueue
*/ */
private Query createQuery(PriorityQueue<ScoreTerm> q) { private Query createQuery(PriorityQueue<ScoreTerm> q) {
BooleanQuery query = new BooleanQuery(); BooleanQuery.Builder query = new BooleanQuery.Builder();
addToQuery(q, query); addToQuery(q, query);
return query; return query.build();
} }
/** /**
* Add to an existing boolean query the More Like This query from this PriorityQueue * Add to an existing boolean query the More Like This query from this PriorityQueue
*/ */
private void addToQuery(PriorityQueue<ScoreTerm> q, BooleanQuery query) { private void addToQuery(PriorityQueue<ScoreTerm> q, BooleanQuery.Builder query) {
ScoreTerm scoreTerm; ScoreTerm scoreTerm;
float bestScore = -1; float bestScore = -1;

View File

@ -180,9 +180,6 @@ public abstract class BaseFuture<V> implements Future<V> {
* pass around a -1 everywhere. * pass around a -1 everywhere.
*/ */
static final class Sync<V> extends AbstractQueuedSynchronizer { static final class Sync<V> extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 0L;
/* Valid states. */ /* Valid states. */
static final int RUNNING = 0; static final int RUNNING = 0;
static final int COMPLETING = 1; static final int COMPLETING = 1;

View File

@ -133,6 +133,9 @@ public class XContentFactory {
* Returns the {@link org.elasticsearch.common.xcontent.XContent} for the provided content type. * Returns the {@link org.elasticsearch.common.xcontent.XContent} for the provided content type.
*/ */
public static XContent xContent(XContentType type) { public static XContent xContent(XContentType type) {
if (type == null) {
throw new IllegalArgumentException("Cannot get xcontent for unknown type");
}
return type.xContent(); return type.xContent();
} }

View File

@ -519,16 +519,17 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
return termsFilter; return termsFilter;
} }
} else { } else {
// Current bool filter requires that at least one should clause matches, even with a must clause. BooleanQuery.Builder typesBool = new BooleanQuery.Builder();
BooleanQuery.Builder bool = new BooleanQuery.Builder();
for (String type : types) { for (String type : types) {
DocumentMapper docMapper = documentMapper(type); DocumentMapper docMapper = documentMapper(type);
if (docMapper == null) { if (docMapper == null) {
bool.add(new TermQuery(new Term(TypeFieldMapper.NAME, type)), BooleanClause.Occur.SHOULD); typesBool.add(new TermQuery(new Term(TypeFieldMapper.NAME, type)), BooleanClause.Occur.SHOULD);
} else { } else {
bool.add(docMapper.typeFilter(), BooleanClause.Occur.SHOULD); typesBool.add(docMapper.typeFilter(), BooleanClause.Occur.SHOULD);
} }
} }
BooleanQuery.Builder bool = new BooleanQuery.Builder();
bool.add(typesBool.build(), Occur.MUST);
if (filterPercolateType) { if (filterPercolateType) {
bool.add(percolatorType, BooleanClause.Occur.MUST_NOT); bool.add(percolatorType, BooleanClause.Occur.MUST_NOT);
} }

View File

@ -875,14 +875,14 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
} }
} }
BooleanQuery boolQuery = new BooleanQuery(); BooleanQuery.Builder boolQuery = new BooleanQuery.Builder();
boolQuery.add(mltQuery, BooleanClause.Occur.SHOULD); boolQuery.add(mltQuery, BooleanClause.Occur.SHOULD);
// exclude the items from the search // exclude the items from the search
if (!include) { if (!include) {
handleExclude(boolQuery, likeItems); handleExclude(boolQuery, likeItems);
} }
return boolQuery; return boolQuery.build();
} }
private static void setDefaultIndexTypeFields(QueryShardContext context, Item item, List<String> moreLikeFields, private static void setDefaultIndexTypeFields(QueryShardContext context, Item item, List<String> moreLikeFields,
@ -949,7 +949,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
return selectedItems.contains(new Item(response.getIndex(), response.getType(), response.getId())); return selectedItems.contains(new Item(response.getIndex(), response.getType(), response.getId()));
} }
private static void handleExclude(BooleanQuery boolQuery, Item[] likeItems) { private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems) {
// artificial docs get assigned a random id and should be disregarded // artificial docs get assigned a random id and should be disregarded
List<BytesRef> uids = new ArrayList<>(); List<BytesRef> uids = new ArrayList<>();
for (Item item : likeItems) { for (Item item : likeItems) {

View File

@ -43,17 +43,12 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
/** Default for flag controlling whether matches are required to be in-order */ /** Default for flag controlling whether matches are required to be in-order */
public static boolean DEFAULT_IN_ORDER = true; public static boolean DEFAULT_IN_ORDER = true;
/** Default for flag controlling whether payloads are collected */
public static boolean DEFAULT_COLLECT_PAYLOADS = true;
private final List<SpanQueryBuilder> clauses = new ArrayList<>(); private final List<SpanQueryBuilder> clauses = new ArrayList<>();
private final int slop; private final int slop;
private boolean inOrder = DEFAULT_IN_ORDER; private boolean inOrder = DEFAULT_IN_ORDER;
private boolean collectPayloads = DEFAULT_COLLECT_PAYLOADS;
static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, 0); static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder(SpanTermQueryBuilder.PROTOTYPE, 0);
/** /**
@ -107,21 +102,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
return this.inOrder; return this.inOrder;
} }
/**
* @param collectPayloads flag controlling whether payloads are collected
*/
public SpanNearQueryBuilder collectPayloads(boolean collectPayloads) {
this.collectPayloads = collectPayloads;
return this;
}
/**
* @see SpanNearQueryBuilder#collectPayloads(boolean)
*/
public boolean collectPayloads() {
return this.collectPayloads;
}
@Override @Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException { protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME); builder.startObject(NAME);
@ -132,7 +112,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
builder.endArray(); builder.endArray();
builder.field(SpanNearQueryParser.SLOP_FIELD.getPreferredName(), slop); builder.field(SpanNearQueryParser.SLOP_FIELD.getPreferredName(), slop);
builder.field(SpanNearQueryParser.IN_ORDER_FIELD.getPreferredName(), inOrder); builder.field(SpanNearQueryParser.IN_ORDER_FIELD.getPreferredName(), inOrder);
builder.field(SpanNearQueryParser.COLLECT_PAYLOADS_FIELD.getPreferredName(), collectPayloads);
printBoostAndQueryName(builder); printBoostAndQueryName(builder);
builder.endObject(); builder.endObject();
} }
@ -145,7 +124,7 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
assert query instanceof SpanQuery; assert query instanceof SpanQuery;
spanQueries[i] = (SpanQuery) query; spanQueries[i] = (SpanQuery) query;
} }
return new SpanNearQuery(spanQueries, slop, inOrder, collectPayloads); return new SpanNearQuery(spanQueries, slop, inOrder);
} }
@Override @Override
@ -155,7 +134,6 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
for (int i = 1; i < clauses.size(); i++) { for (int i = 1; i < clauses.size(); i++) {
queryBuilder.clauses.add((SpanQueryBuilder)clauses.get(i)); queryBuilder.clauses.add((SpanQueryBuilder)clauses.get(i));
} }
queryBuilder.collectPayloads = in.readBoolean();
queryBuilder.inOrder = in.readBoolean(); queryBuilder.inOrder = in.readBoolean();
return queryBuilder; return queryBuilder;
@ -165,20 +143,18 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
protected void doWriteTo(StreamOutput out) throws IOException { protected void doWriteTo(StreamOutput out) throws IOException {
writeQueries(out, clauses); writeQueries(out, clauses);
out.writeVInt(slop); out.writeVInt(slop);
out.writeBoolean(collectPayloads);
out.writeBoolean(inOrder); out.writeBoolean(inOrder);
} }
@Override @Override
protected int doHashCode() { protected int doHashCode() {
return Objects.hash(clauses, slop, collectPayloads, inOrder); return Objects.hash(clauses, slop, inOrder);
} }
@Override @Override
protected boolean doEquals(SpanNearQueryBuilder other) { protected boolean doEquals(SpanNearQueryBuilder other) {
return Objects.equals(clauses, other.clauses) && return Objects.equals(clauses, other.clauses) &&
Objects.equals(slop, other.slop) && Objects.equals(slop, other.slop) &&
Objects.equals(collectPayloads, other.collectPayloads) &&
Objects.equals(inOrder, other.inOrder); Objects.equals(inOrder, other.inOrder);
} }

View File

@ -34,7 +34,7 @@ import java.util.List;
public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> { public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
public static final ParseField SLOP_FIELD = new ParseField("slop"); public static final ParseField SLOP_FIELD = new ParseField("slop");
public static final ParseField COLLECT_PAYLOADS_FIELD = new ParseField("collect_payloads"); public static final ParseField COLLECT_PAYLOADS_FIELD = new ParseField("collect_payloads").withAllDeprecated("no longer supported");
public static final ParseField CLAUSES_FIELD = new ParseField("clauses"); public static final ParseField CLAUSES_FIELD = new ParseField("clauses");
public static final ParseField IN_ORDER_FIELD = new ParseField("in_order"); public static final ParseField IN_ORDER_FIELD = new ParseField("in_order");
@ -50,7 +50,6 @@ public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
float boost = AbstractQueryBuilder.DEFAULT_BOOST; float boost = AbstractQueryBuilder.DEFAULT_BOOST;
Integer slop = null; Integer slop = null;
boolean inOrder = SpanNearQueryBuilder.DEFAULT_IN_ORDER; boolean inOrder = SpanNearQueryBuilder.DEFAULT_IN_ORDER;
boolean collectPayloads = SpanNearQueryBuilder.DEFAULT_COLLECT_PAYLOADS;
String queryName = null; String queryName = null;
List<SpanQueryBuilder> clauses = new ArrayList<>(); List<SpanQueryBuilder> clauses = new ArrayList<>();
@ -76,7 +75,7 @@ public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
if (parseContext.parseFieldMatcher().match(currentFieldName, IN_ORDER_FIELD)) { if (parseContext.parseFieldMatcher().match(currentFieldName, IN_ORDER_FIELD)) {
inOrder = parser.booleanValue(); inOrder = parser.booleanValue();
} else if (parseContext.parseFieldMatcher().match(currentFieldName, COLLECT_PAYLOADS_FIELD)) { } else if (parseContext.parseFieldMatcher().match(currentFieldName, COLLECT_PAYLOADS_FIELD)) {
collectPayloads = parser.booleanValue(); // Deprecated in 3.0.0
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) { } else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) {
slop = parser.intValue(); slop = parser.intValue();
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
@ -104,7 +103,6 @@ public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
queryBuilder.clause(clauses.get(i)); queryBuilder.clause(clauses.get(i));
} }
queryBuilder.inOrder(inOrder); queryBuilder.inOrder(inOrder);
queryBuilder.collectPayloads(collectPayloads);
queryBuilder.boost(boost); queryBuilder.boost(boost);
queryBuilder.queryName(queryName); queryBuilder.queryName(queryName);
return queryBuilder; return queryBuilder;

View File

@ -128,11 +128,11 @@ public class MultiMatchQuery extends MatchQuery {
return groupQuery.get(0); return groupQuery.get(0);
} }
if (groupDismax) { if (groupDismax) {
DisjunctionMaxQuery disMaxQuery = new DisjunctionMaxQuery(tieBreaker); List<Query> queries = new ArrayList<>();
for (Query query : groupQuery) { for (Query query : groupQuery) {
disMaxQuery.add(query); queries.add(query);
} }
return disMaxQuery; return new DisjunctionMaxQuery(queries, tieBreaker);
} else { } else {
final BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder(); final BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
for (Query query : groupQuery) { for (Query query : groupQuery) {

View File

@ -256,6 +256,8 @@ public class IndexingMemoryController extends AbstractComponent implements Index
} finally { } finally {
runLock.unlock(); runLock.unlock();
} }
// Could be while we were checking, more bytes arrived:
totalBytes = bytesWrittenSinceCheck.addAndGet(bytes);
} else { } else {
break; break;
} }

View File

@ -72,8 +72,6 @@ import java.util.Set;
* </ul> * </ul>
*/ */
public final class ClassPermission extends BasicPermission { public final class ClassPermission extends BasicPermission {
private static final long serialVersionUID = 3530711429252193884L;
public static final String STANDARD = "<<STANDARD>>"; public static final String STANDARD = "<<STANDARD>>";
/** Typical set of classes for scripting: basic data types, math, dates, and simple collections */ /** Typical set of classes for scripting: basic data types, math, dates, and simple collections */
// this is the list from the old grovy sandbox impl (+ some things like String, Iterator, etc that were missing) // this is the list from the old grovy sandbox impl (+ some things like String, Iterator, etc that were missing)
@ -144,8 +142,6 @@ public final class ClassPermission extends BasicPermission {
// BasicPermissionCollection only handles wildcards, we expand <<STANDARD>> here // BasicPermissionCollection only handles wildcards, we expand <<STANDARD>> here
PermissionCollection impl = super.newPermissionCollection(); PermissionCollection impl = super.newPermissionCollection();
return new PermissionCollection() { return new PermissionCollection() {
private static final long serialVersionUID = 6792220143549780002L;
@Override @Override
public void add(Permission permission) { public void add(Permission permission) {
if (permission instanceof ClassPermission && STANDARD.equals(permission.getName())) { if (permission instanceof ClassPermission && STANDARD.equals(permission.getName())) {

View File

@ -125,7 +125,20 @@ public class DefaultSearchContext extends SearchContext {
private Sort sort; private Sort sort;
private Float minimumScore; private Float minimumScore;
private boolean trackScores = false; // when sorting, track scores as well... private boolean trackScores = false; // when sorting, track scores as well...
/**
* The original query as sent by the user without the types and aliases
* applied. Putting things in here leaks them into highlighting so don't add
* things like the type filter or alias filters.
*/
private ParsedQuery originalQuery; private ParsedQuery originalQuery;
/**
* Just like originalQuery but with the filters from types and aliases
* applied.
*/
private ParsedQuery filteredQuery;
/**
* The query to actually execute.
*/
private Query query; private Query query;
private ParsedQuery postFilter; private ParsedQuery postFilter;
private Query aliasFilter; private Query aliasFilter;
@ -209,22 +222,7 @@ public class DefaultSearchContext extends SearchContext {
if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) { if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery())); parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery()));
} }
Query searchFilter = searchFilter(types()); filteredQuery(buildFilteredQuery());
if (searchFilter != null) {
if (Queries.isConstantMatchAllQuery(query())) {
Query q = new ConstantScoreQuery(searchFilter);
if (query().getBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
q = new BoostQuery(q, query().getBoost());
}
parsedQuery(new ParsedQuery(q, parsedQuery()));
} else {
BooleanQuery filtered = new BooleanQuery.Builder()
.add(query(), Occur.MUST)
.add(searchFilter, Occur.FILTER)
.build();
parsedQuery(new ParsedQuery(filtered, parsedQuery()));
}
}
try { try {
this.query = searcher().rewrite(this.query); this.query = searcher().rewrite(this.query);
} catch (IOException e) { } catch (IOException e) {
@ -232,6 +230,26 @@ public class DefaultSearchContext extends SearchContext {
} }
} }
private ParsedQuery buildFilteredQuery() {
Query searchFilter = searchFilter(types());
if (searchFilter == null) {
return originalQuery;
}
Query result;
if (Queries.isConstantMatchAllQuery(query())) {
result = new ConstantScoreQuery(searchFilter);
if (query().getBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
result = new BoostQuery(result, query().getBoost());
}
} else {
result = new BooleanQuery.Builder()
.add(query, Occur.MUST)
.add(searchFilter, Occur.FILTER)
.build();
}
return new ParsedQuery(result, originalQuery);
}
@Override @Override
public Query searchFilter(String[] types) { public Query searchFilter(String[] types) {
Query filter = mapperService().searchFilter(types); Query filter = mapperService().searchFilter(types);
@ -546,6 +564,15 @@ public class DefaultSearchContext extends SearchContext {
return this; return this;
} }
public ParsedQuery filteredQuery() {
return filteredQuery;
}
private void filteredQuery(ParsedQuery filteredQuery) {
this.filteredQuery = filteredQuery;
this.query = filteredQuery.query();
}
@Override @Override
public ParsedQuery parsedQuery() { public ParsedQuery parsedQuery() {
return this.originalQuery; return this.originalQuery;

View File

@ -24,8 +24,6 @@ import org.joda.time.chrono.ISOChronology;
import org.joda.time.convert.ConverterManager; import org.joda.time.convert.ConverterManager;
import org.joda.time.convert.InstantConverter; import org.joda.time.convert.InstantConverter;
import java.io.Serializable;
/** /**
* BaseDateTime is an abstract implementation of ReadableDateTime that stores * BaseDateTime is an abstract implementation of ReadableDateTime that stores
* data in <code>long</code> and <code>Chronology</code> fields. * data in <code>long</code> and <code>Chronology</code> fields.
@ -43,13 +41,7 @@ import java.io.Serializable;
*/ */
public abstract class BaseDateTime public abstract class BaseDateTime
extends AbstractDateTime extends AbstractDateTime
implements ReadableDateTime, Serializable { implements ReadableDateTime {
/**
* Serialization lock
*/
private static final long serialVersionUID = -6728882245981L;
/** /**
* The millis from 1970-01-01T00:00:00Z * The millis from 1970-01-01T00:00:00Z
*/ */

View File

@ -159,16 +159,13 @@ public class BlendedTermQueryTests extends ESTestCase {
{ {
BooleanQuery.Builder query = new BooleanQuery.Builder(); BooleanQuery.Builder query = new BooleanQuery.Builder();
query.setDisableCoord(true); query.setDisableCoord(true);
DisjunctionMaxQuery uname = new DisjunctionMaxQuery(0.0f); DisjunctionMaxQuery uname = new DisjunctionMaxQuery(
uname.add(new TermQuery(new Term("username", "foo"))); Arrays.asList(new TermQuery(new Term("username", "foo")), new TermQuery(new Term("song", "foo"))), 0.0f);
uname.add(new TermQuery(new Term("song", "foo")));
DisjunctionMaxQuery s = new DisjunctionMaxQuery(0.0f); DisjunctionMaxQuery s = new DisjunctionMaxQuery(
s.add(new TermQuery(new Term("username", "fighers"))); Arrays.asList(new TermQuery(new Term("username", "fighers")), new TermQuery(new Term("song", "fighers"))), 0.0f);
s.add(new TermQuery(new Term("song", "fighers"))); DisjunctionMaxQuery gen = new DisjunctionMaxQuery(
DisjunctionMaxQuery gen = new DisjunctionMaxQuery(0f); Arrays.asList(new TermQuery(new Term("username", "generator")), new TermQuery(new Term("song", "generator"))), 0f);
gen.add(new TermQuery(new Term("username", "generator")));
gen.add(new TermQuery(new Term("song", "generator")));
query.add(uname, BooleanClause.Occur.SHOULD); query.add(uname, BooleanClause.Occur.SHOULD);
query.add(s, BooleanClause.Occur.SHOULD); query.add(s, BooleanClause.Occur.SHOULD);
query.add(gen, BooleanClause.Occur.SHOULD); query.add(gen, BooleanClause.Occur.SHOULD);

View File

@ -268,7 +268,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
PlainActionFuture<Response> listener = new PlainActionFuture<>(); PlainActionFuture<Response> listener = new PlainActionFuture<>();
action.new AsyncAction(request, listener).start(); action.new AsyncAction(request, listener).start();
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.capturedRequestsByTargetNode(); Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[]{TEST_INDEX}); ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[]{TEST_INDEX});
Set<String> set = new HashSet<>(); Set<String> set = new HashSet<>();
@ -303,7 +303,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
action.new AsyncAction(request, listener).start(); action.new AsyncAction(request, listener).start();
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.capturedRequestsByTargetNode(); Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
// the master should not be in the list of nodes that requests were sent to // the master should not be in the list of nodes that requests were sent to
ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[]{TEST_INDEX}); ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[]{TEST_INDEX});
@ -389,8 +389,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
} }
action.new AsyncAction(request, listener).start(); action.new AsyncAction(request, listener).start();
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.capturedRequestsByTargetNode(); Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
transport.clear();
ShardsIterator shardIt = clusterService.state().getRoutingTable().allShards(new String[]{TEST_INDEX}); ShardsIterator shardIt = clusterService.state().getRoutingTable().allShards(new String[]{TEST_INDEX});
Map<String, List<ShardRouting>> map = new HashMap<>(); Map<String, List<ShardRouting>> map = new HashMap<>();

View File

@ -68,6 +68,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -193,7 +194,8 @@ public class TransportReplicationActionTests extends ESTestCase {
final IndexShardRoutingTable shardRoutingTable = clusterService.state().routingTable().index(index).shard(shardId.id()); final IndexShardRoutingTable shardRoutingTable = clusterService.state().routingTable().index(index).shard(shardId.id());
final String primaryNodeId = shardRoutingTable.primaryShard().currentNodeId(); final String primaryNodeId = shardRoutingTable.primaryShard().currentNodeId();
final List<CapturingTransport.CapturedRequest> capturedRequests = transport.capturedRequestsByTargetNode().get(primaryNodeId); final List<CapturingTransport.CapturedRequest> capturedRequests =
transport.getCapturedRequestsByTargetNodeAndClear().get(primaryNodeId);
assertThat(capturedRequests, notNullValue()); assertThat(capturedRequests, notNullValue());
assertThat(capturedRequests.size(), equalTo(1)); assertThat(capturedRequests.size(), equalTo(1));
assertThat(capturedRequests.get(0).action, equalTo("testAction[p]")); assertThat(capturedRequests.get(0).action, equalTo("testAction[p]"));
@ -235,7 +237,7 @@ public class TransportReplicationActionTests extends ESTestCase {
reroutePhase.run(); reroutePhase.run();
assertThat(request.shardId(), equalTo(shardId)); assertThat(request.shardId(), equalTo(shardId));
logger.info("--> primary is assigned to [{}], checking request forwarded", primaryNodeId); logger.info("--> primary is assigned to [{}], checking request forwarded", primaryNodeId);
final List<CapturingTransport.CapturedRequest> capturedRequests = transport.capturedRequestsByTargetNode().get(primaryNodeId); final List<CapturingTransport.CapturedRequest> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear().get(primaryNodeId);
assertThat(capturedRequests, notNullValue()); assertThat(capturedRequests, notNullValue());
assertThat(capturedRequests.size(), equalTo(1)); assertThat(capturedRequests.size(), equalTo(1));
if (clusterService.state().nodes().localNodeId().equals(primaryNodeId)) { if (clusterService.state().nodes().localNodeId().equals(primaryNodeId)) {
@ -256,7 +258,7 @@ public class TransportReplicationActionTests extends ESTestCase {
primaryPhase.run(); primaryPhase.run();
assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true)); assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true));
final String replicaNodeId = clusterService.state().getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards().get(0).currentNodeId(); final String replicaNodeId = clusterService.state().getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards().get(0).currentNodeId();
final List<CapturingTransport.CapturedRequest> requests = transport.capturedRequestsByTargetNode().get(replicaNodeId); final List<CapturingTransport.CapturedRequest> requests = transport.getCapturedRequestsByTargetNodeAndClear().get(replicaNodeId);
assertThat(requests, notNullValue()); assertThat(requests, notNullValue());
assertThat(requests.size(), equalTo(1)); assertThat(requests.size(), equalTo(1));
assertThat("replica request was not sent", requests.get(0).action, equalTo("testAction[r]")); assertThat("replica request was not sent", requests.get(0).action, equalTo("testAction[r]"));
@ -286,8 +288,9 @@ public class TransportReplicationActionTests extends ESTestCase {
TransportReplicationAction<Request, Request, Response>.PrimaryPhase primaryPhase = actionWithAddedReplicaAfterPrimaryOp.new PrimaryPhase(request, createTransportChannel(listener)); TransportReplicationAction<Request, Request, Response>.PrimaryPhase primaryPhase = actionWithAddedReplicaAfterPrimaryOp.new PrimaryPhase(request, createTransportChannel(listener));
primaryPhase.run(); primaryPhase.run();
assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true)); assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true));
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequestsByTargetNode = transport.getCapturedRequestsByTargetNodeAndClear();
for (ShardRouting replica : stateWithAddedReplicas.getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards()) { for (ShardRouting replica : stateWithAddedReplicas.getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards()) {
List<CapturingTransport.CapturedRequest> requests = transport.capturedRequestsByTargetNode().get(replica.currentNodeId()); List<CapturingTransport.CapturedRequest> requests = capturedRequestsByTargetNode.get(replica.currentNodeId());
assertThat(requests, notNullValue()); assertThat(requests, notNullValue());
assertThat(requests.size(), equalTo(1)); assertThat(requests.size(), equalTo(1));
assertThat("replica request was not sent", requests.get(0).action, equalTo("testAction[r]")); assertThat("replica request was not sent", requests.get(0).action, equalTo("testAction[r]"));
@ -319,8 +322,9 @@ public class TransportReplicationActionTests extends ESTestCase {
primaryPhase.run(); primaryPhase.run();
assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true)); assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true));
ShardRouting relocatingReplicaShard = stateWithRelocatingReplica.getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards().get(0); ShardRouting relocatingReplicaShard = stateWithRelocatingReplica.getRoutingTable().shardRoutingTable(index, shardId.id()).replicaShards().get(0);
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequestsByTargetNode = transport.getCapturedRequestsByTargetNodeAndClear();
for (String node : new String[] {relocatingReplicaShard.currentNodeId(), relocatingReplicaShard.relocatingNodeId()}) { for (String node : new String[] {relocatingReplicaShard.currentNodeId(), relocatingReplicaShard.relocatingNodeId()}) {
List<CapturingTransport.CapturedRequest> requests = transport.capturedRequestsByTargetNode().get(node); List<CapturingTransport.CapturedRequest> requests = capturedRequestsByTargetNode.get(node);
assertThat(requests, notNullValue()); assertThat(requests, notNullValue());
assertThat(requests.size(), equalTo(1)); assertThat(requests.size(), equalTo(1));
assertThat("replica request was not sent to replica", requests.get(0).action, equalTo("testAction[r]")); assertThat("replica request was not sent to replica", requests.get(0).action, equalTo("testAction[r]"));
@ -489,8 +493,7 @@ public class TransportReplicationActionTests extends ESTestCase {
assertThat(replicationPhase.totalShards(), equalTo(totalShards)); assertThat(replicationPhase.totalShards(), equalTo(totalShards));
assertThat(replicationPhase.pending(), equalTo(assignedReplicas)); assertThat(replicationPhase.pending(), equalTo(assignedReplicas));
replicationPhase.run(); replicationPhase.run();
final CapturingTransport.CapturedRequest[] capturedRequests = transport.capturedRequests(); final CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
transport.clear();
HashMap<String, Request> nodesSentTo = new HashMap<>(); HashMap<String, Request> nodesSentTo = new HashMap<>();
boolean executeOnReplica = boolean executeOnReplica =
@ -544,8 +547,7 @@ public class TransportReplicationActionTests extends ESTestCase {
logger.debug("--> simulating failure on {} with [{}]", capturedRequest.node, t.getClass().getSimpleName()); logger.debug("--> simulating failure on {} with [{}]", capturedRequest.node, t.getClass().getSimpleName());
transport.handleResponse(capturedRequest.requestId, t); transport.handleResponse(capturedRequest.requestId, t);
if (criticalFailure) { if (criticalFailure) {
CapturingTransport.CapturedRequest[] shardFailedRequests = transport.capturedRequests(); CapturingTransport.CapturedRequest[] shardFailedRequests = transport.getCapturedRequestsAndClear();
transport.clear();
assertEquals(1, shardFailedRequests.length); assertEquals(1, shardFailedRequests.length);
CapturingTransport.CapturedRequest shardFailedRequest = shardFailedRequests[0]; CapturingTransport.CapturedRequest shardFailedRequest = shardFailedRequests[0];
// get the shard the request was sent to // get the shard the request was sent to
@ -636,19 +638,17 @@ public class TransportReplicationActionTests extends ESTestCase {
assertThat(transport.capturedRequests().length, equalTo(1)); assertThat(transport.capturedRequests().length, equalTo(1));
// try once with successful response // try once with successful response
transport.handleResponse(transport.capturedRequests()[0].requestId, TransportResponse.Empty.INSTANCE); transport.handleResponse(transport.capturedRequests()[0].requestId, TransportResponse.Empty.INSTANCE);
assertIndexShardCounter(1);
transport.clear(); transport.clear();
assertIndexShardCounter(1);
request = new Request(shardId).timeout("100ms"); request = new Request(shardId).timeout("100ms");
primaryPhase = action.new PrimaryPhase(request, createTransportChannel(listener)); primaryPhase = action.new PrimaryPhase(request, createTransportChannel(listener));
primaryPhase.run(); primaryPhase.run();
assertIndexShardCounter(2); assertIndexShardCounter(2);
CapturingTransport.CapturedRequest[] replicationRequests = transport.capturedRequests(); CapturingTransport.CapturedRequest[] replicationRequests = transport.getCapturedRequestsAndClear();
transport.clear();
assertThat(replicationRequests.length, equalTo(1)); assertThat(replicationRequests.length, equalTo(1));
// try with failure response // try with failure response
transport.handleResponse(replicationRequests[0].requestId, new CorruptIndexException("simulated", (String) null)); transport.handleResponse(replicationRequests[0].requestId, new CorruptIndexException("simulated", (String) null));
CapturingTransport.CapturedRequest[] shardFailedRequests = transport.capturedRequests(); CapturingTransport.CapturedRequest[] shardFailedRequests = transport.getCapturedRequestsAndClear();
transport.clear();
assertEquals(1, shardFailedRequests.length); assertEquals(1, shardFailedRequests.length);
transport.handleResponse(shardFailedRequests[0].requestId, TransportResponse.Empty.INSTANCE); transport.handleResponse(shardFailedRequests[0].requestId, TransportResponse.Empty.INSTANCE);
assertIndexShardCounter(1); assertIndexShardCounter(1);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.action.update; package org.elasticsearch.action.update;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
@ -166,4 +167,15 @@ public class UpdateRequestTests extends ESTestCase {
indexAction = (IndexRequest) action; indexAction = (IndexRequest) action;
assertThat(indexAction.ttl(), is(providedTTLValue)); assertThat(indexAction.ttl(), is(providedTTLValue));
} }
// Related to issue #15822
public void testInvalidBodyThrowsParseException() throws Exception {
UpdateRequest request = new UpdateRequest("test", "type", "1");
try {
request.source(new byte[] { (byte) '"' });
fail("Should have thrown a ElasticsearchParseException");
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), equalTo("Failed to derive xcontent"));
}
}
} }

View File

@ -135,8 +135,7 @@ public class ShardStateActionTests extends ESTestCase {
} }
}); });
final CapturingTransport.CapturedRequest[] capturedRequests = transport.capturedRequests(); final CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
transport.clear();
assertThat(capturedRequests.length, equalTo(1)); assertThat(capturedRequests.length, equalTo(1));
assert !failure.get(); assert !failure.get();
transport.handleResponse(capturedRequests[0].requestId, new TransportException("simulated")); transport.handleResponse(capturedRequests[0].requestId, new TransportException("simulated"));
@ -171,8 +170,7 @@ public class ShardStateActionTests extends ESTestCase {
progress.set(true); progress.set(true);
assertTrue(timedOut.get()); assertTrue(timedOut.get());
final CapturingTransport.CapturedRequest[] capturedRequests = transport.capturedRequests(); final CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
transport.clear();
assertThat(capturedRequests.length, equalTo(1)); assertThat(capturedRequests.length, equalTo(1));
} }

View File

@ -34,6 +34,7 @@ import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;

View File

@ -28,6 +28,8 @@ import com.spatial4j.core.shape.impl.PointImpl;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.LineStringBuilder; import org.elasticsearch.common.geo.builders.LineStringBuilder;
import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.builders.PolygonBuilder;
import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder;
@ -50,7 +52,7 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testNewRectangle() { public void testNewRectangle() {
Rectangle rectangle = ShapeBuilders.newEnvelope().topLeft(-45, 30).bottomRight(45, -30).build(); Rectangle rectangle = ShapeBuilders.newEnvelope(new Coordinate(-45, 30), new Coordinate(45, -30)).build();
assertEquals(-45D, rectangle.getMinX(), 0.0d); assertEquals(-45D, rectangle.getMinX(), 0.0d);
assertEquals(-30D, rectangle.getMinY(), 0.0d); assertEquals(-30D, rectangle.getMinY(), 0.0d);
assertEquals(45D, rectangle.getMaxX(), 0.0d); assertEquals(45D, rectangle.getMaxX(), 0.0d);
@ -58,12 +60,12 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testNewPolygon() { public void testNewPolygon() {
Polygon polygon = ShapeBuilders.newPolygon() Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-45, 30) .coordinate(-45, 30)
.point(45, 30) .coordinate(45, 30)
.point(45, -30) .coordinate(45, -30)
.point(-45, -30) .coordinate(-45, -30)
.point(-45, 30).toPolygon(); .coordinate(-45, 30)).toPolygon();
LineString exterior = polygon.getExteriorRing(); LineString exterior = polygon.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30)); assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
@ -73,12 +75,12 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testNewPolygon_coordinate() { public void testNewPolygon_coordinate() {
Polygon polygon = ShapeBuilders.newPolygon() Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(new Coordinate(-45, 30)) .coordinate(new Coordinate(-45, 30))
.point(new Coordinate(45, 30)) .coordinate(new Coordinate(45, 30))
.point(new Coordinate(45, -30)) .coordinate(new Coordinate(45, -30))
.point(new Coordinate(-45, -30)) .coordinate(new Coordinate(-45, -30))
.point(new Coordinate(-45, 30)).toPolygon(); .coordinate(new Coordinate(-45, 30))).toPolygon();
LineString exterior = polygon.getExteriorRing(); LineString exterior = polygon.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30)); assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
@ -88,8 +90,9 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testNewPolygon_coordinates() { public void testNewPolygon_coordinates() {
Polygon polygon = ShapeBuilders.newPolygon() Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.points(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30)).toPolygon(); .coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30))
).toPolygon();
LineString exterior = polygon.getExteriorRing(); LineString exterior = polygon.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30)); assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
@ -100,86 +103,93 @@ public class ShapeBuilderTests extends ESTestCase {
public void testLineStringBuilder() { public void testLineStringBuilder() {
// Building a simple LineString // Building a simple LineString
ShapeBuilders.newLineString() ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(-130.0, 55.0) .coordinate(-130.0, 55.0)
.point(-130.0, -40.0) .coordinate(-130.0, -40.0)
.point(-15.0, -40.0) .coordinate(-15.0, -40.0)
.point(-20.0, 50.0) .coordinate(-20.0, 50.0)
.point(-45.0, 50.0) .coordinate(-45.0, 50.0)
.point(-45.0, -15.0) .coordinate(-45.0, -15.0)
.point(-110.0, -15.0) .coordinate(-110.0, -15.0)
.point(-110.0, 55.0).build(); .coordinate(-110.0, 55.0)).build();
// Building a linestring that needs to be wrapped // Building a linestring that needs to be wrapped
ShapeBuilders.newLineString() ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(100.0, 50.0) .coordinate(100.0, 50.0)
.point(110.0, -40.0) .coordinate(110.0, -40.0)
.point(240.0, -40.0) .coordinate(240.0, -40.0)
.point(230.0, 60.0) .coordinate(230.0, 60.0)
.point(200.0, 60.0) .coordinate(200.0, 60.0)
.point(200.0, -30.0) .coordinate(200.0, -30.0)
.point(130.0, -30.0) .coordinate(130.0, -30.0)
.point(130.0, 60.0) .coordinate(130.0, 60.0)
)
.build(); .build();
// Building a lineString on the dateline // Building a lineString on the dateline
ShapeBuilders.newLineString() ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(-180.0, 80.0) .coordinate(-180.0, 80.0)
.point(-180.0, 40.0) .coordinate(-180.0, 40.0)
.point(-180.0, -40.0) .coordinate(-180.0, -40.0)
.point(-180.0, -80.0) .coordinate(-180.0, -80.0)
)
.build(); .build();
// Building a lineString on the dateline // Building a lineString on the dateline
ShapeBuilders.newLineString() ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(180.0, 80.0) .coordinate(180.0, 80.0)
.point(180.0, 40.0) .coordinate(180.0, 40.0)
.point(180.0, -40.0) .coordinate(180.0, -40.0)
.point(180.0, -80.0) .coordinate(180.0, -80.0)
)
.build(); .build();
} }
public void testMultiLineString() { public void testMultiLineString() {
ShapeBuilders.newMultiLinestring() ShapeBuilders.newMultiLinestring()
.linestring(new LineStringBuilder() .linestring(new LineStringBuilder(new CoordinatesBuilder()
.point(-100.0, 50.0) .coordinate(-100.0, 50.0)
.point(50.0, 50.0) .coordinate(50.0, 50.0)
.point(50.0, 20.0) .coordinate(50.0, 20.0)
.point(-100.0, 20.0) .coordinate(-100.0, 20.0)
)
) )
.linestring(new LineStringBuilder() .linestring(new LineStringBuilder(new CoordinatesBuilder()
.point(-100.0, 20.0) .coordinate(-100.0, 20.0)
.point(50.0, 20.0) .coordinate(50.0, 20.0)
.point(50.0, 0.0) .coordinate(50.0, 0.0)
.point(-100.0, 0.0) .coordinate(-100.0, 0.0)
)
) )
.build(); .build();
// LineString that needs to be wrappped // LineString that needs to be wrappped
ShapeBuilders.newMultiLinestring() ShapeBuilders.newMultiLinestring()
.linestring(new LineStringBuilder() .linestring(new LineStringBuilder(new CoordinatesBuilder()
.point(150.0, 60.0) .coordinate(150.0, 60.0)
.point(200.0, 60.0) .coordinate(200.0, 60.0)
.point(200.0, 40.0) .coordinate(200.0, 40.0)
.point(150.0, 40.0) .coordinate(150.0, 40.0)
)
)
.linestring(new LineStringBuilder(new CoordinatesBuilder()
.coordinate(150.0, 20.0)
.coordinate(200.0, 20.0)
.coordinate(200.0, 0.0)
.coordinate(150.0, 0.0)
) )
.linestring(new LineStringBuilder()
.point(150.0, 20.0)
.point(200.0, 20.0)
.point(200.0, 0.0)
.point(150.0, 0.0)
) )
.build(); .build();
} }
public void testPolygonSelfIntersection() { public void testPolygonSelfIntersection() {
try { try {
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-40.0, 50.0) .coordinate(-40.0, 50.0)
.point(40.0, 50.0) .coordinate(40.0, 50.0)
.point(-40.0, -50.0) .coordinate(-40.0, -50.0)
.point(40.0, -50.0) .coordinate(40.0, -50.0).close())
.close().build(); .build();
fail("Expected InvalidShapeException"); fail("Expected InvalidShapeException");
} catch (InvalidShapeException e) { } catch (InvalidShapeException e) {
assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0")); assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0"));
@ -212,22 +222,26 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testPolygonWrapping() { public void testPolygonWrapping() {
Shape shape = ShapeBuilders.newPolygon() Shape shape = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-150.0, 65.0) .coordinate(-150.0, 65.0)
.point(-250.0, 65.0) .coordinate(-250.0, 65.0)
.point(-250.0, -65.0) .coordinate(-250.0, -65.0)
.point(-150.0, -65.0) .coordinate(-150.0, -65.0)
.close().build(); .close()
)
.build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
} }
public void testLineStringWrapping() { public void testLineStringWrapping() {
Shape shape = ShapeBuilders.newLineString() Shape shape = ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(-150.0, 65.0) .coordinate(-150.0, 65.0)
.point(-250.0, 65.0) .coordinate(-250.0, 65.0)
.point(-250.0, -65.0) .coordinate(-250.0, -65.0)
.point(-150.0, -65.0) .coordinate(-150.0, -65.0)
.close()
)
.build(); .build();
assertMultiLineString(shape); assertMultiLineString(shape);
} }
@ -238,36 +252,39 @@ public class ShapeBuilderTests extends ESTestCase {
// expected results: 3 polygons, 1 with a hole // expected results: 3 polygons, 1 with a hole
// a giant c shape // a giant c shape
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(174,0) .coordinate(174,0)
.point(-176,0) .coordinate(-176,0)
.point(-176,3) .coordinate(-176,3)
.point(177,3) .coordinate(177,3)
.point(177,5) .coordinate(177,5)
.point(-176,5) .coordinate(-176,5)
.point(-176,8) .coordinate(-176,8)
.point(174,8) .coordinate(174,8)
.point(174,0); .coordinate(174,0)
);
// 3/4 of an embedded 'c', crossing dateline once // 3/4 of an embedded 'c', crossing dateline once
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(175, 1) .coordinate(175, 1)
.point(175, 7) .coordinate(175, 7)
.point(-178, 7) .coordinate(-178, 7)
.point(-178, 6) .coordinate(-178, 6)
.point(176, 6) .coordinate(176, 6)
.point(176, 2) .coordinate(176, 2)
.point(179, 2) .coordinate(179, 2)
.point(179,1) .coordinate(179,1)
.point(175, 1)); .coordinate(175, 1)
));
// embedded hole right of the dateline // embedded hole right of the dateline
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-179, 1) .coordinate(-179, 1)
.point(-179, 2) .coordinate(-179, 2)
.point(-177, 2) .coordinate(-177, 2)
.point(-177,1) .coordinate(-177,1)
.point(-179,1)); .coordinate(-179,1)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
@ -279,141 +296,150 @@ public class ShapeBuilderTests extends ESTestCase {
// expected results: 3 polygons, 1 with a hole // expected results: 3 polygons, 1 with a hole
// a giant c shape // a giant c shape
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-186,0) .coordinate(-186,0)
.point(-176,0) .coordinate(-176,0)
.point(-176,3) .coordinate(-176,3)
.point(-183,3) .coordinate(-183,3)
.point(-183,5) .coordinate(-183,5)
.point(-176,5) .coordinate(-176,5)
.point(-176,8) .coordinate(-176,8)
.point(-186,8) .coordinate(-186,8)
.point(-186,0); .coordinate(-186,0)
);
// 3/4 of an embedded 'c', crossing dateline once // 3/4 of an embedded 'c', crossing dateline once
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-185,1) .coordinate(-185,1)
.point(-181,1) .coordinate(-181,1)
.point(-181,2) .coordinate(-181,2)
.point(-184,2) .coordinate(-184,2)
.point(-184,6) .coordinate(-184,6)
.point(-178,6) .coordinate(-178,6)
.point(-178,7) .coordinate(-178,7)
.point(-185,7) .coordinate(-185,7)
.point(-185,1)); .coordinate(-185,1)
));
// embedded hole right of the dateline // embedded hole right of the dateline
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-179,1) .coordinate(-179,1)
.point(-177,1) .coordinate(-177,1)
.point(-177,2) .coordinate(-177,2)
.point(-179,2) .coordinate(-179,2)
.point(-179,1)); .coordinate(-179,1)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
} }
public void testComplexShapeWithHole() { public void testComplexShapeWithHole() {
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-85.0018514,37.1311314) .coordinate(-85.0018514,37.1311314)
.point(-85.0016645,37.1315293) .coordinate(-85.0016645,37.1315293)
.point(-85.0016246,37.1317069) .coordinate(-85.0016246,37.1317069)
.point(-85.0016526,37.1318183) .coordinate(-85.0016526,37.1318183)
.point(-85.0017119,37.1319196) .coordinate(-85.0017119,37.1319196)
.point(-85.0019371,37.1321182) .coordinate(-85.0019371,37.1321182)
.point(-85.0019972,37.1322115) .coordinate(-85.0019972,37.1322115)
.point(-85.0019942,37.1323234) .coordinate(-85.0019942,37.1323234)
.point(-85.0019543,37.1324336) .coordinate(-85.0019543,37.1324336)
.point(-85.001906,37.1324985) .coordinate(-85.001906,37.1324985)
.point(-85.001834,37.1325497) .coordinate(-85.001834,37.1325497)
.point(-85.0016965,37.1325907) .coordinate(-85.0016965,37.1325907)
.point(-85.0016011,37.1325873) .coordinate(-85.0016011,37.1325873)
.point(-85.0014816,37.1325353) .coordinate(-85.0014816,37.1325353)
.point(-85.0011755,37.1323509) .coordinate(-85.0011755,37.1323509)
.point(-85.000955,37.1322802) .coordinate(-85.000955,37.1322802)
.point(-85.0006241,37.1322529) .coordinate(-85.0006241,37.1322529)
.point(-85.0000002,37.1322307) .coordinate(-85.0000002,37.1322307)
.point(-84.9994,37.1323001) .coordinate(-84.9994,37.1323001)
.point(-84.999109,37.1322864) .coordinate(-84.999109,37.1322864)
.point(-84.998934,37.1322415) .coordinate(-84.998934,37.1322415)
.point(-84.9988639,37.1321888) .coordinate(-84.9988639,37.1321888)
.point(-84.9987841,37.1320944) .coordinate(-84.9987841,37.1320944)
.point(-84.9987208,37.131954) .coordinate(-84.9987208,37.131954)
.point(-84.998736,37.1316611) .coordinate(-84.998736,37.1316611)
.point(-84.9988091,37.131334) .coordinate(-84.9988091,37.131334)
.point(-84.9989283,37.1311337) .coordinate(-84.9989283,37.1311337)
.point(-84.9991943,37.1309198) .coordinate(-84.9991943,37.1309198)
.point(-84.9993573,37.1308459) .coordinate(-84.9993573,37.1308459)
.point(-84.9995888,37.1307924) .coordinate(-84.9995888,37.1307924)
.point(-84.9998746,37.130806) .coordinate(-84.9998746,37.130806)
.point(-85.0000002,37.1308358) .coordinate(-85.0000002,37.1308358)
.point(-85.0004984,37.1310658) .coordinate(-85.0004984,37.1310658)
.point(-85.0008008,37.1311625) .coordinate(-85.0008008,37.1311625)
.point(-85.0009461,37.1311684) .coordinate(-85.0009461,37.1311684)
.point(-85.0011373,37.1311515) .coordinate(-85.0011373,37.1311515)
.point(-85.0016455,37.1310491) .coordinate(-85.0016455,37.1310491)
.point(-85.0018514,37.1311314); .coordinate(-85.0018514,37.1311314)
);
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-85.0000002,37.1317672) .coordinate(-85.0000002,37.1317672)
.point(-85.0001983,37.1317538) .coordinate(-85.0001983,37.1317538)
.point(-85.0003378,37.1317582) .coordinate(-85.0003378,37.1317582)
.point(-85.0004697,37.131792) .coordinate(-85.0004697,37.131792)
.point(-85.0008048,37.1319439) .coordinate(-85.0008048,37.1319439)
.point(-85.0009342,37.1319838) .coordinate(-85.0009342,37.1319838)
.point(-85.0010184,37.1319463) .coordinate(-85.0010184,37.1319463)
.point(-85.0010618,37.13184) .coordinate(-85.0010618,37.13184)
.point(-85.0010057,37.1315102) .coordinate(-85.0010057,37.1315102)
.point(-85.000977,37.1314403) .coordinate(-85.000977,37.1314403)
.point(-85.0009182,37.1313793) .coordinate(-85.0009182,37.1313793)
.point(-85.0005366,37.1312209) .coordinate(-85.0005366,37.1312209)
.point(-85.000224,37.1311466) .coordinate(-85.000224,37.1311466)
.point(-85.000087,37.1311356) .coordinate(-85.000087,37.1311356)
.point(-85.0000002,37.1311433) .coordinate(-85.0000002,37.1311433)
.point(-84.9995021,37.1312336) .coordinate(-84.9995021,37.1312336)
.point(-84.9993308,37.1312859) .coordinate(-84.9993308,37.1312859)
.point(-84.9992567,37.1313252) .coordinate(-84.9992567,37.1313252)
.point(-84.9991868,37.1314277) .coordinate(-84.9991868,37.1314277)
.point(-84.9991593,37.1315381) .coordinate(-84.9991593,37.1315381)
.point(-84.9991841,37.1316527) .coordinate(-84.9991841,37.1316527)
.point(-84.9992329,37.1317117) .coordinate(-84.9992329,37.1317117)
.point(-84.9993527,37.1317788) .coordinate(-84.9993527,37.1317788)
.point(-84.9994931,37.1318061) .coordinate(-84.9994931,37.1318061)
.point(-84.9996815,37.1317979) .coordinate(-84.9996815,37.1317979)
.point(-85.0000002,37.1317672)); .coordinate(-85.0000002,37.1317672)
)
);
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
} }
public void testShapeWithHoleAtEdgeEndPoints() { public void testShapeWithHoleAtEdgeEndPoints() {
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-4, 2) .coordinate(-4, 2)
.point(4, 2) .coordinate(4, 2)
.point(6, 0) .coordinate(6, 0)
.point(4, -2) .coordinate(4, -2)
.point(-4, -2) .coordinate(-4, -2)
.point(-6, 0) .coordinate(-6, 0)
.point(-4, 2); .coordinate(-4, 2)
);
builder.hole(new LineStringBuilder() builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(4, 1) .coordinate(4, 1)
.point(4, -1) .coordinate(4, -1)
.point(-4, -1) .coordinate(-4, -1)
.point(-4, 1) .coordinate(-4, 1)
.point(4, 1)); .coordinate(4, 1)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
} }
public void testShapeWithPointOnDateline() { public void testShapeWithPointOnDateline() {
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(180, 0) .coordinate(180, 0)
.point(176, 4) .coordinate(176, 4)
.point(176, -4) .coordinate(176, -4)
.point(180, 0); .coordinate(180, 0)
);
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
@ -421,21 +447,23 @@ public class ShapeBuilderTests extends ESTestCase {
public void testShapeWithEdgeAlongDateline() { public void testShapeWithEdgeAlongDateline() {
// test case 1: test the positive side of the dateline // test case 1: test the positive side of the dateline
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(180, 0) .coordinate(180, 0)
.point(176, 4) .coordinate(176, 4)
.point(180, -4) .coordinate(180, -4)
.point(180, 0); .coordinate(180, 0)
);
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
// test case 2: test the negative side of the dateline // test case 2: test the negative side of the dateline
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-176, 4) .coordinate(-176, 4)
.point(-180, 0) .coordinate(-180, 0)
.point(-180, -4) .coordinate(-180, -4)
.point(-176, 4); .coordinate(-176, 4)
);
shape = builder.close().build(); shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
@ -443,73 +471,85 @@ public class ShapeBuilderTests extends ESTestCase {
public void testShapeWithBoundaryHoles() { public void testShapeWithBoundaryHoles() {
// test case 1: test the positive side of the dateline // test case 1: test the positive side of the dateline
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-177, 10) .coordinate(-177, 10)
.point(176, 15) .coordinate(176, 15)
.point(172, 0) .coordinate(172, 0)
.point(176, -15) .coordinate(176, -15)
.point(-177, -10) .coordinate(-177, -10)
.point(-177, 10); .coordinate(-177, 10)
builder.hole(new LineStringBuilder() );
.point(176, 10) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(180, 5) .coordinate(176, 10)
.point(180, -5) .coordinate(180, 5)
.point(176, -10) .coordinate(180, -5)
.point(176, 10)); .coordinate(176, -10)
.coordinate(176, 10)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
// test case 2: test the negative side of the dateline // test case 2: test the negative side of the dateline
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(
.point(-176, 15) new CoordinatesBuilder()
.point(179, 10) .coordinate(-176, 15)
.point(179, -10) .coordinate(179, 10)
.point(-176, -15) .coordinate(179, -10)
.point(-172, 0); .coordinate(-176, -15)
builder.hole(new LineStringBuilder() .coordinate(-172, 0)
.point(-176, 10) .close()
.point(-176, -10) );
.point(-180, -5) builder.hole(new LineStringBuilder(
.point(-180, 5) new CoordinatesBuilder()
.point(-176, 10)); .coordinate(-176, 10)
.coordinate(-176, -10)
.coordinate(-180, -5)
.coordinate(-180, 5)
.coordinate(-176, 10)
.close()
));
shape = builder.close().build(); shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
} }
public void testShapeWithTangentialHole() { public void testShapeWithTangentialHole() {
// test a shape with one tangential (shared) vertex (should pass) // test a shape with one tangential (shared) vertex (should pass)
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(179, 10) .coordinate(179, 10)
.point(168, 15) .coordinate(168, 15)
.point(164, 0) .coordinate(164, 0)
.point(166, -15) .coordinate(166, -15)
.point(179, -10) .coordinate(179, -10)
.point(179, 10); .coordinate(179, 10)
builder.hole(new LineStringBuilder() );
.point(-177, 10) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-178, -10) .coordinate(-177, 10)
.point(-180, -5) .coordinate(-178, -10)
.point(-180, 5) .coordinate(-180, -5)
.point(-177, 10)); .coordinate(-180, 5)
.coordinate(-177, 10)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
} }
public void testShapeWithInvalidTangentialHole() { public void testShapeWithInvalidTangentialHole() {
// test a shape with one invalid tangential (shared) vertex (should throw exception) // test a shape with one invalid tangential (shared) vertex (should throw exception)
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(179, 10) .coordinate(179, 10)
.point(168, 15) .coordinate(168, 15)
.point(164, 0) .coordinate(164, 0)
.point(166, -15) .coordinate(166, -15)
.point(179, -10) .coordinate(179, -10)
.point(179, 10); .coordinate(179, 10)
builder.hole(new LineStringBuilder() );
.point(164, 0) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(175, 10) .coordinate(164, 0)
.point(175, 5) .coordinate(175, 10)
.point(179, -10) .coordinate(175, 5)
.point(164, 0)); .coordinate(179, -10)
.coordinate(164, 0)
));
try { try {
builder.close().build(); builder.close().build();
fail("Expected InvalidShapeException"); fail("Expected InvalidShapeException");
@ -520,43 +560,48 @@ public class ShapeBuilderTests extends ESTestCase {
public void testBoundaryShapeWithTangentialHole() { public void testBoundaryShapeWithTangentialHole() {
// test a shape with one tangential (shared) vertex for each hole (should pass) // test a shape with one tangential (shared) vertex for each hole (should pass)
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-177, 10) .coordinate(-177, 10)
.point(176, 15) .coordinate(176, 15)
.point(172, 0) .coordinate(172, 0)
.point(176, -15) .coordinate(176, -15)
.point(-177, -10) .coordinate(-177, -10)
.point(-177, 10); .coordinate(-177, 10)
builder.hole(new LineStringBuilder() );
.point(-177, 10) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-178, -10) .coordinate(-177, 10)
.point(-180, -5) .coordinate(-178, -10)
.point(-180, 5) .coordinate(-180, -5)
.point(-177, 10)); .coordinate(-180, 5)
builder.hole(new LineStringBuilder() .coordinate(-177, 10)
.point(172, 0) ));
.point(176, 10) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(176, -5) .coordinate(172, 0)
.point(172, 0)); .coordinate(176, 10)
.coordinate(176, -5)
.coordinate(172, 0)
));
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertMultiPolygon(shape); assertMultiPolygon(shape);
} }
public void testBoundaryShapeWithInvalidTangentialHole() { public void testBoundaryShapeWithInvalidTangentialHole() {
// test shape with two tangential (shared) vertices (should throw exception) // test shape with two tangential (shared) vertices (should throw exception)
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-177, 10) .coordinate(-177, 10)
.point(176, 15) .coordinate(176, 15)
.point(172, 0) .coordinate(172, 0)
.point(176, -15) .coordinate(176, -15)
.point(-177, -10) .coordinate(-177, -10)
.point(-177, 10); .coordinate(-177, 10)
builder.hole(new LineStringBuilder() );
.point(-177, 10) builder.hole(new LineStringBuilder(new CoordinatesBuilder()
.point(172, 0) .coordinate(-177, 10)
.point(180, -5) .coordinate(172, 0)
.point(176, -10) .coordinate(180, -5)
.point(-177, 10)); .coordinate(176, -10)
.coordinate(-177, 10)
));
try { try {
builder.close().build(); builder.close().build();
fail("Expected InvalidShapeException"); fail("Expected InvalidShapeException");
@ -569,11 +614,12 @@ public class ShapeBuilderTests extends ESTestCase {
* Test an enveloping polygon around the max mercator bounds * Test an enveloping polygon around the max mercator bounds
*/ */
public void testBoundaryShape() { public void testBoundaryShape() {
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-180, 90) .coordinate(-180, 90)
.point(180, 90) .coordinate(180, 90)
.point(180, -90) .coordinate(180, -90)
.point(-180, -90); .coordinate(-180, 90)
);
Shape shape = builder.close().build(); Shape shape = builder.close().build();
@ -582,21 +628,23 @@ public class ShapeBuilderTests extends ESTestCase {
public void testShapeWithAlternateOrientation() { public void testShapeWithAlternateOrientation() {
// cw: should produce a multi polygon spanning hemispheres // cw: should produce a multi polygon spanning hemispheres
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(180, 0) .coordinate(180, 0)
.point(176, 4) .coordinate(176, 4)
.point(-176, 4) .coordinate(-176, 4)
.point(180, 0); .coordinate(180, 0)
);
Shape shape = builder.close().build(); Shape shape = builder.close().build();
assertPolygon(shape); assertPolygon(shape);
// cw: geo core will convert to ccw across the dateline // cw: geo core will convert to ccw across the dateline
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(180, 0) .coordinate(180, 0)
.point(-176, 4) .coordinate(-176, 4)
.point(176, 4) .coordinate(176, 4)
.point(180, 0); .coordinate(180, 0)
);
shape = builder.close().build(); shape = builder.close().build();
@ -604,12 +652,13 @@ public class ShapeBuilderTests extends ESTestCase {
} }
public void testInvalidShapeWithConsecutiveDuplicatePoints() { public void testInvalidShapeWithConsecutiveDuplicatePoints() {
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(180, 0) .coordinate(180, 0)
.point(176, 4) .coordinate(176, 4)
.point(176, 4) .coordinate(176, 4)
.point(-176, 4) .coordinate(-176, 4)
.point(180, 0); .coordinate(180, 0)
);
try { try {
builder.close().build(); builder.close().build();
fail("Expected InvalidShapeException"); fail("Expected InvalidShapeException");

View File

@ -40,7 +40,7 @@ import static org.hamcrest.Matchers.not;
public abstract class AbstractShapeBuilderTestCase<SB extends ShapeBuilder> extends ESTestCase { public abstract class AbstractShapeBuilderTestCase<SB extends ShapeBuilder> extends ESTestCase {
private static final int NUMBER_OF_TESTBUILDERS = 20; private static final int NUMBER_OF_TESTBUILDERS = 100;
private static NamedWriteableRegistry namedWriteableRegistry; private static NamedWriteableRegistry namedWriteableRegistry;
/** /**

View File

@ -42,9 +42,18 @@ public class CircleBuilderTests extends AbstractShapeBuilderTestCase<CircleBuild
DistanceUnit unit = original.unit(); DistanceUnit unit = original.unit();
if (randomBoolean()) { if (randomBoolean()) {
mutation.center(new Coordinate(original.center().x/2, original.center().y/2)); if (original.center().x > 0.0 || original.center().y > 0.0) {
mutation.center(new Coordinate(original.center().x/2, original.center().y/2));
} else {
// original center was 0.0, 0.0
mutation.center(randomDouble() + 0.1, randomDouble() + 0.1);
}
} else if (randomBoolean()) { } else if (randomBoolean()) {
radius = radius/2; if (radius > 0) {
radius = radius/2;
} else {
radius = randomDouble() + 0.1;
}
} else { } else {
DistanceUnit newRandom = unit; DistanceUnit newRandom = unit;
while (newRandom == unit) { while (newRandom == unit) {
@ -56,10 +65,15 @@ public class CircleBuilderTests extends AbstractShapeBuilderTestCase<CircleBuild
} }
static CircleBuilder createRandomShape() { static CircleBuilder createRandomShape() {
double centerX = randomDoubleBetween(-180, 180, false); CircleBuilder circle = new CircleBuilder();
double centerY = randomDoubleBetween(-90, 90, false); if (frequently()) {
return new CircleBuilder() double centerX = randomDoubleBetween(-180, 180, false);
.center(new Coordinate(centerX, centerY)) double centerY = randomDoubleBetween(-90, 90, false);
.radius(randomDoubleBetween(0.1, 10.0, false), randomFrom(DistanceUnit.values())); circle.center(centerX, centerY);
}
if (randomBoolean()) {
circle.radius(randomDoubleBetween(0.1, 10.0, false), randomFrom(DistanceUnit.values()));
}
return circle;
} }
} }

View File

@ -25,8 +25,26 @@ import org.elasticsearch.test.geo.RandomShapeGenerator;
import java.io.IOException; import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
public class EnvelopeBuilderTests extends AbstractShapeBuilderTestCase<EnvelopeBuilder> { public class EnvelopeBuilderTests extends AbstractShapeBuilderTestCase<EnvelopeBuilder> {
public void testInvalidConstructorArgs() {
try {
new EnvelopeBuilder(null, new Coordinate(1.0, -1.0));
fail("Exception expected");
} catch (NullPointerException e) {
assertThat("topLeft of envelope cannot be null", equalTo(e.getMessage()));
}
try {
new EnvelopeBuilder(new Coordinate(1.0, -1.0), null);
fail("Exception expected");
} catch (NullPointerException e) {
assertThat("bottomRight of envelope cannot be null", equalTo(e.getMessage()));
}
}
@Override @Override
protected EnvelopeBuilder createTestShapeBuilder() { protected EnvelopeBuilder createTestShapeBuilder() {
return createRandomShape(); return createRandomShape();
@ -42,26 +60,25 @@ public class EnvelopeBuilderTests extends AbstractShapeBuilderTestCase<EnvelopeB
// move one corner to the middle of original // move one corner to the middle of original
switch (randomIntBetween(0, 3)) { switch (randomIntBetween(0, 3)) {
case 0: case 0:
mutation.topLeft(new Coordinate(randomDoubleBetween(-180.0, original.bottomRight().x, true), original.topLeft().y)); mutation = new EnvelopeBuilder(new Coordinate(randomDoubleBetween(-180.0, original.bottomRight().x, true), original.topLeft().y), original.bottomRight());
break; break;
case 1: case 1:
mutation.topLeft(new Coordinate(original.topLeft().x, randomDoubleBetween(original.bottomRight().y, 90.0, true))); mutation = new EnvelopeBuilder(new Coordinate(original.topLeft().x, randomDoubleBetween(original.bottomRight().y, 90.0, true)), original.bottomRight());
break; break;
case 2: case 2:
mutation.bottomRight(new Coordinate(randomDoubleBetween(original.topLeft().x, 180.0, true), original.bottomRight().y)); mutation = new EnvelopeBuilder(original.topLeft(), new Coordinate(randomDoubleBetween(original.topLeft().x, 180.0, true), original.bottomRight().y));
break; break;
case 3: case 3:
mutation.bottomRight(new Coordinate(original.bottomRight().x, randomDoubleBetween(-90.0, original.topLeft().y, true))); mutation = new EnvelopeBuilder(original.topLeft(), new Coordinate(original.bottomRight().x, randomDoubleBetween(-90.0, original.topLeft().y, true)));
break; break;
} }
return mutation; return mutation;
} }
static EnvelopeBuilder createRandomShape() { static EnvelopeBuilder createRandomShape() {
EnvelopeBuilder envelope = new EnvelopeBuilder();
Rectangle box = RandomShapeGenerator.xRandomRectangle(getRandom(), RandomShapeGenerator.xRandomPoint(getRandom())); Rectangle box = RandomShapeGenerator.xRandomRectangle(getRandom(), RandomShapeGenerator.xRandomPoint(getRandom()));
envelope.topLeft(box.getMinX(), box.getMaxY()) EnvelopeBuilder envelope = new EnvelopeBuilder(new Coordinate(box.getMinX(), box.getMaxY()),
.bottomRight(box.getMaxX(), box.getMinY()); new Coordinate(box.getMaxX(), box.getMinY()));
return envelope; return envelope;
} }
} }

View File

@ -20,13 +20,40 @@
package org.elasticsearch.common.geo.builders; package org.elasticsearch.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.test.geo.RandomShapeGenerator; import org.elasticsearch.test.geo.RandomShapeGenerator;
import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType; import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
public class LineStringBuilderTests extends AbstractShapeBuilderTestCase<LineStringBuilder> { public class LineStringBuilderTests extends AbstractShapeBuilderTestCase<LineStringBuilder> {
public void testInvalidConstructorArgs() {
try {
new LineStringBuilder((List<Coordinate>) null);
fail("Exception expected");
} catch (IllegalArgumentException e) {
assertThat("cannot create point collection with empty set of points", equalTo(e.getMessage()));
}
try {
new LineStringBuilder(new CoordinatesBuilder());
fail("Exception expected");
} catch (IllegalArgumentException e) {
assertThat("cannot create point collection with empty set of points", equalTo(e.getMessage()));
}
try {
new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0));
fail("Exception expected");
} catch (IllegalArgumentException e) {
assertThat("invalid number of points in LineString (found [1] - must be >= 2)", equalTo(e.getMessage()));
}
}
@Override @Override
protected LineStringBuilder createTestShapeBuilder() { protected LineStringBuilder createTestShapeBuilder() {
return createRandomShape(); return createRandomShape();
@ -54,7 +81,7 @@ public class LineStringBuilderTests extends AbstractShapeBuilderTestCase<LineStr
coordinate.y = randomDoubleBetween(-90.0, 90.0, true); coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
} }
} }
return mutation.points(coordinates); return mutation.coordinates(coordinates);
} }
static LineStringBuilder createRandomShape() { static LineStringBuilder createRandomShape() {

View File

@ -40,30 +40,37 @@ public class MultiLineStringBuilderTests extends AbstractShapeBuilderTestCase<Mu
static MultiLineStringBuilder mutate(MultiLineStringBuilder original) throws IOException { static MultiLineStringBuilder mutate(MultiLineStringBuilder original) throws IOException {
MultiLineStringBuilder mutation = (MultiLineStringBuilder) copyShape(original); MultiLineStringBuilder mutation = (MultiLineStringBuilder) copyShape(original);
Coordinate[][] coordinates = mutation.coordinates(); Coordinate[][] coordinates = mutation.coordinates();
int lineToChange = randomInt(coordinates.length - 1); if (coordinates.length > 0) {
for (int i = 0; i < coordinates.length; i++) { int lineToChange = randomInt(coordinates.length - 1);
Coordinate[] line = coordinates[i]; for (int i = 0; i < coordinates.length; i++) {
if (i == lineToChange) { Coordinate[] line = coordinates[i];
Coordinate coordinate = randomFrom(line); if (i == lineToChange) {
if (randomBoolean()) { Coordinate coordinate = randomFrom(line);
if (coordinate.x != 0.0) { if (randomBoolean()) {
coordinate.x = coordinate.x / 2; if (coordinate.x != 0.0) {
coordinate.x = coordinate.x / 2;
} else {
coordinate.x = randomDoubleBetween(-180.0, 180.0, true);
}
} else { } else {
coordinate.x = randomDoubleBetween(-180.0, 180.0, true); if (coordinate.y != 0.0) {
} coordinate.y = coordinate.y / 2;
} else { } else {
if (coordinate.y != 0.0) { coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
coordinate.y = coordinate.y / 2; }
} else {
coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
} }
} }
} }
} else {
mutation.linestring((LineStringBuilder) RandomShapeGenerator.createShape(getRandom(), ShapeType.LINESTRING));
} }
return mutation; return mutation;
} }
static MultiLineStringBuilder createRandomShape() { static MultiLineStringBuilder createRandomShape() {
if (true) {
return new MultiLineStringBuilder();
}
return (MultiLineStringBuilder) RandomShapeGenerator.createShape(getRandom(), ShapeType.MULTILINESTRING); return (MultiLineStringBuilder) RandomShapeGenerator.createShape(getRandom(), ShapeType.MULTILINESTRING);
} }
} }

View File

@ -25,8 +25,29 @@ import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType;
import java.io.IOException; import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
public class MultiPointBuilderTests extends AbstractShapeBuilderTestCase<MultiPointBuilder> { public class MultiPointBuilderTests extends AbstractShapeBuilderTestCase<MultiPointBuilder> {
public void testInvalidBuilderException() {
try {
new MultiPointBuilder(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertThat("cannot create point collection with empty set of points", equalTo(e.getMessage()));
}
try {
new MultiPointBuilder(new CoordinatesBuilder().build());
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertThat("cannot create point collection with empty set of points", equalTo(e.getMessage()));
}
// one point is minimum
new MultiPointBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0).build());
}
@Override @Override
protected MultiPointBuilder createTestShapeBuilder() { protected MultiPointBuilder createTestShapeBuilder() {
return createRandomShape(); return createRandomShape();
@ -40,21 +61,25 @@ public class MultiPointBuilderTests extends AbstractShapeBuilderTestCase<MultiPo
static MultiPointBuilder mutate(MultiPointBuilder original) throws IOException { static MultiPointBuilder mutate(MultiPointBuilder original) throws IOException {
MultiPointBuilder mutation = (MultiPointBuilder) copyShape(original); MultiPointBuilder mutation = (MultiPointBuilder) copyShape(original);
Coordinate[] coordinates = original.coordinates(false); Coordinate[] coordinates = original.coordinates(false);
Coordinate coordinate = randomFrom(coordinates); if (coordinates.length > 0) {
if (randomBoolean()) { Coordinate coordinate = randomFrom(coordinates);
if (coordinate.x != 0.0) { if (randomBoolean()) {
coordinate.x = coordinate.x / 2; if (coordinate.x != 0.0) {
coordinate.x = coordinate.x / 2;
} else {
coordinate.x = randomDoubleBetween(-180.0, 180.0, true);
}
} else { } else {
coordinate.x = randomDoubleBetween(-180.0, 180.0, true); if (coordinate.y != 0.0) {
coordinate.y = coordinate.y / 2;
} else {
coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
}
} }
} else { } else {
if (coordinate.y != 0.0) { coordinates = new Coordinate[]{new Coordinate(1.0, 1.0)};
coordinate.y = coordinate.y / 2;
} else {
coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
}
} }
return mutation.points(coordinates); return mutation.coordinates(coordinates);
} }
static MultiPointBuilder createRandomShape() { static MultiPointBuilder createRandomShape() {

View File

@ -20,12 +20,15 @@
package org.elasticsearch.common.geo.builders; package org.elasticsearch.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation; import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation;
import org.elasticsearch.test.geo.RandomShapeGenerator; import org.elasticsearch.test.geo.RandomShapeGenerator;
import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType; import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType;
import java.io.IOException; import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
public class PolygonBuilderTests extends AbstractShapeBuilderTestCase<PolygonBuilder> { public class PolygonBuilderTests extends AbstractShapeBuilderTestCase<PolygonBuilder> {
@Override @Override
@ -77,8 +80,7 @@ public class PolygonBuilderTests extends AbstractShapeBuilderTestCase<PolygonBui
* This is done so we don't have to expose a setter for orientation in the actual class * This is done so we don't have to expose a setter for orientation in the actual class
*/ */
private static PolygonBuilder polyWithOposingOrientation(PolygonBuilder pb) { private static PolygonBuilder polyWithOposingOrientation(PolygonBuilder pb) {
PolygonBuilder mutation = new PolygonBuilder(pb.orientation() == Orientation.LEFT ? Orientation.RIGHT : Orientation.LEFT); PolygonBuilder mutation = new PolygonBuilder(pb.shell(), pb.orientation() == Orientation.LEFT ? Orientation.RIGHT : Orientation.LEFT);
mutation.points(pb.shell().coordinates(false));
for (LineStringBuilder hole : pb.holes()) { for (LineStringBuilder hole : pb.holes()) {
mutation.hole(hole); mutation.hole(hole);
} }
@ -92,4 +94,33 @@ public class PolygonBuilderTests extends AbstractShapeBuilderTestCase<PolygonBui
} }
return pgb; return pgb;
} }
public void testCoerceShell() {
try{
new PolygonBuilder(new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0)
.coordinate(1.0, 0.0).coordinate(1.0, 1.0).build()), Orientation.RIGHT);
fail("should raise validation exception");
} catch (IllegalArgumentException e) {
assertEquals("invalid number of points in LinearRing (found [3] - must be >= 4)", e.getMessage());
}
PolygonBuilder pb = new PolygonBuilder(new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0)
.coordinate(1.0, 0.0).coordinate(1.0, 1.0).build()), Orientation.RIGHT, true);
assertThat("Shell should have been closed via coerce", pb.shell().coordinates(false).length, equalTo(4));
}
public void testCoerceHole() {
PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(0.0, 0.0)
.coordinate(2.0, 0.0).coordinate(2.0, 2.0).coordinate(0.0, 0.0));
try{
pb.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0,0.0).coordinate(1.0,0.0).coordinate(1.0,1.0).build()));
fail("should raise validation exception");
} catch (IllegalArgumentException e) {
assertEquals("invalid number of points in LinearRing (found [3] - must be >= 4)", e.getMessage());
}
pb.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(0.0,0.0).coordinate(1.0,0.0).coordinate(1.0,1.0).build()), true);
assertThat("hole should have been closed via coerce", pb.holes().get(0).coordinates(false).length, equalTo(4));
}
} }

View File

@ -97,6 +97,14 @@ public class XContentFactoryTests extends ESTestCase {
assertNull(XContentFactory.xContentType(is)); assertNull(XContentFactory.xContentType(is));
} }
public void testInvalidStream() throws Exception {
byte[] bytes = new byte[] { (byte) '"' };
assertNull(XContentFactory.xContentType(bytes));
bytes = new byte[] { (byte) 'x' };
assertNull(XContentFactory.xContentType(bytes));
}
public void testJsonFromBytesOptionallyPrecededByUtf8Bom() throws Exception { public void testJsonFromBytesOptionallyPrecededByUtf8Bom() throws Exception {
byte[] bytes = new byte[] {(byte) '{', (byte) '}'}; byte[] bytes = new byte[] {(byte) '{', (byte) '}'};
assertThat(XContentFactory.xContentType(bytes), equalTo(XContentType.JSON)); assertThat(XContentFactory.xContentType(bytes), equalTo(XContentType.JSON));

View File

@ -19,9 +19,17 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -32,6 +40,7 @@ import java.util.HashSet;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.hasToString;
public class MapperServiceTests extends ESSingleNodeTestCase { public class MapperServiceTests extends ESSingleNodeTestCase {
@ -122,4 +131,22 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
} }
assertFalse(indexService.mapperService().hasMapping(MapperService.DEFAULT_MAPPING)); assertFalse(indexService.mapperService().hasMapping(MapperService.DEFAULT_MAPPING));
} }
public void testSearchFilter() {
IndexService indexService = createIndex("index1", client().admin().indices().prepareCreate("index1")
.addMapping("type1", "field1", "type=nested")
.addMapping("type2", new Object[0])
);
Query searchFilter = indexService.mapperService().searchFilter("type1", "type3");
Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new ConstantScoreQuery(new TermQuery(new Term(TypeFieldMapper.NAME, "type1"))), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TypeFieldMapper.NAME, "type3")), BooleanClause.Occur.SHOULD)
.build(), BooleanClause.Occur.MUST
)
.add(Queries.newNonNestedFilter(), BooleanClause.Occur.MUST)
.build();
assertThat(searchFilter, equalTo(new ConstantScoreQuery(expectedQuery)));
}
} }

View File

@ -204,6 +204,7 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
double distance = queryBuilder.distance(); double distance = queryBuilder.distance();
if (queryBuilder.geoDistance() != null) { if (queryBuilder.geoDistance() != null) {
distance = queryBuilder.geoDistance().normalize(distance, DistanceUnit.DEFAULT); distance = queryBuilder.geoDistance().normalize(distance, DistanceUnit.DEFAULT);
distance = org.elasticsearch.common.geo.GeoUtils.maxRadialDistance(queryBuilder.point(), distance);
assertThat(geoQuery.getRadiusMeters(), closeTo(distance, GeoUtils.TOLERANCE)); assertThat(geoQuery.getRadiusMeters(), closeTo(distance, GeoUtils.TOLERANCE));
} }
} }

View File

@ -19,6 +19,8 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import com.vividsolutions.jts.geom.Coordinate;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
@ -215,7 +217,7 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
// see #3878 // see #3878
public void testThatXContentSerializationInsideOfArrayWorks() throws Exception { public void testThatXContentSerializationInsideOfArrayWorks() throws Exception {
EnvelopeBuilder envelopeBuilder = ShapeBuilders.newEnvelope().topLeft(0, 0).bottomRight(10, 10); EnvelopeBuilder envelopeBuilder = ShapeBuilders.newEnvelope(new Coordinate(0, 0), new Coordinate(10, 10));
GeoShapeQueryBuilder geoQuery = QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder); GeoShapeQueryBuilder geoQuery = QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder);
JsonXContent.contentBuilder().startArray().value(geoQuery).endArray(); JsonXContent.contentBuilder().startArray().value(geoQuery).endArray();
} }

View File

@ -23,6 +23,7 @@ import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.ShapeBuilders; import org.elasticsearch.common.geo.builders.ShapeBuilders;
import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
@ -174,12 +175,14 @@ public class QueryDSLDocumentationTests extends ESTestCase {
public void testGeoShape() throws IOException { public void testGeoShape() throws IOException {
GeoShapeQueryBuilder qb = geoShapeQuery( GeoShapeQueryBuilder qb = geoShapeQuery(
"pin.location", "pin.location",
ShapeBuilders.newMultiPoint() ShapeBuilders.newMultiPoint(
.point(0, 0) new CoordinatesBuilder()
.point(0, 10) .coordinate(0, 0)
.point(10, 10) .coordinate(0, 10)
.point(10, 0) .coordinate(10, 10)
.point(0, 0)); .coordinate(10, 0)
.coordinate(0, 0)
.build()));
qb.relation(ShapeRelation.WITHIN); qb.relation(ShapeRelation.WITHIN);
qb = geoShapeQuery( qb = geoShapeQuery(
@ -331,8 +334,7 @@ public class QueryDSLDocumentationTests extends ESTestCase {
spanNearQuery(spanTermQuery("field","value1"), 12) spanNearQuery(spanTermQuery("field","value1"), 12)
.clause(spanTermQuery("field","value2")) .clause(spanTermQuery("field","value2"))
.clause(spanTermQuery("field","value3")) .clause(spanTermQuery("field","value3"))
.inOrder(false) .inOrder(false);
.collectPayloads(false);
} }
public void testSpanNot() { public void testSpanNot() {

View File

@ -77,7 +77,6 @@ public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase<SpanC
" } ],\n" + " } ],\n" +
" \"slop\" : 5,\n" + " \"slop\" : 5,\n" +
" \"in_order\" : true,\n" + " \"in_order\" : true,\n" +
" \"collect_payloads\" : true,\n" +
" \"boost\" : 1.0\n" + " \"boost\" : 1.0\n" +
" }\n" + " }\n" +
" },\n" + " },\n" +

View File

@ -22,6 +22,8 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanQuery;
import org.elasticsearch.Version;
import org.elasticsearch.common.ParseFieldMatcher;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
@ -38,7 +40,6 @@ public class SpanNearQueryBuilderTests extends AbstractQueryTestCase<SpanNearQue
queryBuilder.clause(spanTermQueries[i]); queryBuilder.clause(spanTermQueries[i]);
} }
queryBuilder.inOrder(randomBoolean()); queryBuilder.inOrder(randomBoolean());
queryBuilder.collectPayloads(randomBoolean());
return queryBuilder; return queryBuilder;
} }
@ -100,7 +101,6 @@ public class SpanNearQueryBuilderTests extends AbstractQueryTestCase<SpanNearQue
" } ],\n" + " } ],\n" +
" \"slop\" : 12,\n" + " \"slop\" : 12,\n" +
" \"in_order\" : false,\n" + " \"in_order\" : false,\n" +
" \"collect_payloads\" : false,\n" +
" \"boost\" : 1.0\n" + " \"boost\" : 1.0\n" +
" }\n" + " }\n" +
"}"; "}";
@ -111,6 +111,42 @@ public class SpanNearQueryBuilderTests extends AbstractQueryTestCase<SpanNearQue
assertEquals(json, 3, parsed.clauses().size()); assertEquals(json, 3, parsed.clauses().size());
assertEquals(json, 12, parsed.slop()); assertEquals(json, 12, parsed.slop());
assertEquals(json, false, parsed.inOrder()); assertEquals(json, false, parsed.inOrder());
assertEquals(json, false, parsed.collectPayloads()); }
public void testCollectPayloadsDeprecated() throws Exception {
assertEquals("We can remove support for ignoring collect_payloads in 4.0", 3, Version.CURRENT.major);
String json =
"{\n" +
" \"span_near\" : {\n" +
" \"clauses\" : [ {\n" +
" \"span_term\" : {\n" +
" \"field\" : {\n" +
" \"value\" : \"value1\",\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" }, {\n" +
" \"span_term\" : {\n" +
" \"field\" : {\n" +
" \"value\" : \"value2\",\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" }, {\n" +
" \"span_term\" : {\n" +
" \"field\" : {\n" +
" \"value\" : \"value3\",\n" +
" \"boost\" : 1.0\n" +
" }\n" +
" }\n" +
" } ],\n" +
" \"slop\" : 12,\n" +
" \"in_order\" : false,\n" +
" \"collect_payloads\" : false,\n" +
" \"boost\" : 1.0\n" +
" }\n" +
"}";
parseQuery(json, ParseFieldMatcher.EMPTY); // Just don't throw an error and we're fine
} }
} }

View File

@ -214,7 +214,6 @@ public class SpanNotQueryBuilderTests extends AbstractQueryTestCase<SpanNotQuery
" } ],\n" + " } ],\n" +
" \"slop\" : 0,\n" + " \"slop\" : 0,\n" +
" \"in_order\" : true,\n" + " \"in_order\" : true,\n" +
" \"collect_payloads\" : true,\n" +
" \"boost\" : 1.0\n" + " \"boost\" : 1.0\n" +
" }\n" + " }\n" +
" },\n" + " },\n" +

View File

@ -77,7 +77,6 @@ public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase<SpanWithi
" } ],\n" + " } ],\n" +
" \"slop\" : 5,\n" + " \"slop\" : 5,\n" +
" \"in_order\" : true,\n" + " \"in_order\" : true,\n" +
" \"collect_payloads\" : true,\n" +
" \"boost\" : 1.0\n" + " \"boost\" : 1.0\n" +
" }\n" + " }\n" +
" },\n" + " },\n" +

View File

@ -23,6 +23,7 @@ import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils; import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.exception.InvalidShapeException; import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.Shape;
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy; import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree; import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgs; import org.apache.lucene.spatial.query.SpatialArgs;
@ -40,6 +41,7 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.LineStringBuilder; import org.elasticsearch.common.geo.builders.LineStringBuilder;
import org.elasticsearch.common.geo.builders.MultiPolygonBuilder; import org.elasticsearch.common.geo.builders.MultiPolygonBuilder;
import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.builders.PolygonBuilder;
@ -119,30 +121,29 @@ public class GeoFilterIT extends ESIntegTestCase {
public void testShapeBuilders() { public void testShapeBuilders() {
try { try {
// self intersection polygon // self intersection polygon
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10) .coordinate(-10, -10)
.point(10, 10) .coordinate(10, 10)
.point(-10, 10) .coordinate(-10, 10)
.point(10, -10) .coordinate(10, -10)
.close().build(); .close())
.build();
fail("Self intersection not detected"); fail("Self intersection not detected");
} catch (InvalidShapeException e) { } catch (InvalidShapeException e) {
} }
// polygon with hole // polygon with hole
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10) .coordinate(-10, -10).coordinate(-10, 10).coordinate(10, 10).coordinate(10, -10).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-5, -5).coordinate(-5, 5).coordinate(5, 5).coordinate(5, -5).close()))
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5) .build();
.close()).close().build();
try { try {
// polygon with overlapping hole // polygon with overlapping hole
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10) .coordinate(-10, -10).coordinate(-10, 10).coordinate(10, 10).coordinate(10, -10).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-5, -5).point(-5, 11).point(5, 11).point(5, -5) .coordinate(-5, -5).coordinate(-5, 11).coordinate(5, 11).coordinate(5, -5).close()))
.close()).close().build(); .build();
fail("Self intersection not detected"); fail("Self intersection not detected");
} catch (InvalidShapeException e) { } catch (InvalidShapeException e) {
@ -150,30 +151,27 @@ public class GeoFilterIT extends ESIntegTestCase {
try { try {
// polygon with intersection holes // polygon with intersection holes
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10) .coordinate(-10, -10).coordinate(-10, 10).coordinate(10, 10).coordinate(10, -10).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-5, -5).coordinate(-5, 5).coordinate(5, 5).coordinate(5, -5).close()))
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5) .hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-5, -6).coordinate(5, -6).coordinate(5, -4).coordinate(-5, -4).close()))
.close()) .build();
.hole(new LineStringBuilder()
.point(-5, -6).point(5, -6).point(5, -4).point(-5, -4)
.close())
.close().build();
fail("Intersection of holes not detected"); fail("Intersection of holes not detected");
} catch (InvalidShapeException e) { } catch (InvalidShapeException e) {
} }
try { try {
// Common line in polygon // Common line in polygon
ShapeBuilders.newPolygon() ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10) .coordinate(-10, -10)
.point(-10, 10) .coordinate(-10, 10)
.point(-5, 10) .coordinate(-5, 10)
.point(-5, -5) .coordinate(-5, -5)
.point(-5, 20) .coordinate(-5, 20)
.point(10, 20) .coordinate(10, 20)
.point(10, -10) .coordinate(10, -10)
.close().build(); .close())
.build();
fail("Self intersection not detected"); fail("Self intersection not detected");
} catch (InvalidShapeException e) { } catch (InvalidShapeException e) {
} }
@ -181,23 +179,22 @@ public class GeoFilterIT extends ESIntegTestCase {
// Multipolygon: polygon with hole and polygon within the whole // Multipolygon: polygon with hole and polygon within the whole
ShapeBuilders ShapeBuilders
.newMultiPolygon() .newMultiPolygon()
.polygon(new PolygonBuilder() .polygon(new PolygonBuilder(
.point(-10, -10) new CoordinatesBuilder().coordinate(-10, -10)
.point(-10, 10) .coordinate(-10, 10)
.point(10, 10) .coordinate(10, 10)
.point(10, -10) .coordinate(10, -10).close())
.hole(new LineStringBuilder().point(-5, -5) .hole(new LineStringBuilder(
.point(-5, 5) new CoordinatesBuilder().coordinate(-5, -5)
.point(5, 5) .coordinate(-5, 5)
.point(5, -5) .coordinate(5, 5)
.close()) .coordinate(5, -5).close())))
.close()) .polygon(new PolygonBuilder(
.polygon(new PolygonBuilder() new CoordinatesBuilder()
.point(-4, -4) .coordinate(-4, -4)
.point(-4, 4) .coordinate(-4, 4)
.point(4, 4) .coordinate(4, 4)
.point(4, -4) .coordinate(4, -4).close()))
.close())
.build(); .build();
} }
@ -226,14 +223,12 @@ public class GeoFilterIT extends ESIntegTestCase {
// with a hole of size 5x5 equidistant from all sides. This hole in turn contains // with a hole of size 5x5 equidistant from all sides. This hole in turn contains
// the second polygon of size 4x4 equidistant from all sites // the second polygon of size 4x4 equidistant from all sites
MultiPolygonBuilder polygon = ShapeBuilders.newMultiPolygon() MultiPolygonBuilder polygon = ShapeBuilders.newMultiPolygon()
.polygon(new PolygonBuilder() .polygon(new PolygonBuilder(
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10) new CoordinatesBuilder().coordinate(-10, -10).coordinate(-10, 10).coordinate(10, 10).coordinate(10, -10).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5).close()) .coordinate(-5, -5).coordinate(-5, 5).coordinate(5, 5).coordinate(5, -5).close())))
.close()) .polygon(new PolygonBuilder(
.polygon(new PolygonBuilder() new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()));
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4).close());
BytesReference data = jsonBuilder().startObject().field("area", polygon).endObject().bytes(); BytesReference data = jsonBuilder().startObject().field("area", polygon).endObject().bytes();
client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet(); client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();
@ -292,11 +287,10 @@ public class GeoFilterIT extends ESIntegTestCase {
} }
// Create a polygon that fills the empty area of the polygon defined above // Create a polygon that fills the empty area of the polygon defined above
PolygonBuilder inverse = ShapeBuilders.newPolygon() PolygonBuilder inverse = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5) .coordinate(-5, -5).coordinate(-5, 5).coordinate(5, 5).coordinate(5, -5).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4).close()) new CoordinatesBuilder().coordinate(-4, -4).coordinate(-4, 4).coordinate(4, 4).coordinate(4, -4).close()));
.close();
data = jsonBuilder().startObject().field("area", inverse).endObject().bytes(); data = jsonBuilder().startObject().field("area", inverse).endObject().bytes();
client().prepareIndex("shapes", "polygon", "2").setSource(data).execute().actionGet(); client().prepareIndex("shapes", "polygon", "2").setSource(data).execute().actionGet();
@ -311,16 +305,15 @@ public class GeoFilterIT extends ESIntegTestCase {
assertFirstHit(result, hasId("2")); assertFirstHit(result, hasId("2"));
// Create Polygon with hole and common edge // Create Polygon with hole and common edge
PolygonBuilder builder = ShapeBuilders.newPolygon() PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10) .coordinate(-10, -10).coordinate(-10, 10).coordinate(10, 10).coordinate(10, -10).close())
.hole(new LineStringBuilder() .hole(new LineStringBuilder(new CoordinatesBuilder()
.point(-5, -5).point(-5, 5).point(10, 5).point(10, -5).close()) .coordinate(-5, -5).coordinate(-5, 5).coordinate(10, 5).coordinate(10, -5).close()));
.close();
if (withinSupport) { if (withinSupport) {
// Polygon WithIn Polygon // Polygon WithIn Polygon
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(-30, -30).point(-30, 30).point(30, 30).point(30, -30).close(); .coordinate(-30, -30).coordinate(-30, 30).coordinate(30, 30).coordinate(30, -30).close());
result = client().prepareSearch() result = client().prepareSearch()
.setQuery(matchAllQuery()) .setQuery(matchAllQuery())
@ -330,19 +323,17 @@ public class GeoFilterIT extends ESIntegTestCase {
} }
// Create a polygon crossing longitude 180. // Create a polygon crossing longitude 180.
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(170, -10).point(190, -10).point(190, 10).point(170, 10) .coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close());
.close();
data = jsonBuilder().startObject().field("area", builder).endObject().bytes(); data = jsonBuilder().startObject().field("area", builder).endObject().bytes();
client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet(); client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet(); client().admin().indices().prepareRefresh().execute().actionGet();
// Create a polygon crossing longitude 180 with hole. // Create a polygon crossing longitude 180 with hole.
builder = ShapeBuilders.newPolygon() builder = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(170, -10).point(190, -10).point(190, 10).point(170, 10) .coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close())
.hole(new LineStringBuilder().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close()) .hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, -5).coordinate(185, -5).coordinate(185, 5).coordinate(175, 5).close()));
.close();
data = jsonBuilder().startObject().field("area", builder).endObject().bytes(); data = jsonBuilder().startObject().field("area", builder).endObject().bytes();
client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet(); client().prepareIndex("shapes", "polygon", "1").setSource(data).execute().actionGet();

View File

@ -20,9 +20,12 @@
package org.elasticsearch.search.geo; package org.elasticsearch.search.geo;
import com.spatial4j.core.shape.Rectangle; import com.spatial4j.core.shape.Rectangle;
import com.vividsolutions.jts.geom.Coordinate;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.EnvelopeBuilder; import org.elasticsearch.common.geo.builders.EnvelopeBuilder;
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder; import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
import org.elasticsearch.common.geo.builders.LineStringBuilder; import org.elasticsearch.common.geo.builders.LineStringBuilder;
@ -94,7 +97,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
.endObject() .endObject()
.endObject()).setRefresh(true).execute().actionGet(); .endObject()).setRefresh(true).execute().actionGet();
ShapeBuilder shape = ShapeBuilders.newEnvelope().topLeft(-45, 45).bottomRight(45, -45); ShapeBuilder shape = ShapeBuilders.newEnvelope(new Coordinate(-45, 45), new Coordinate(45, -45));
SearchResponse searchResponse = client().prepareSearch("test").setTypes("type1") SearchResponse searchResponse = client().prepareSearch("test").setTypes("type1")
.setQuery(geoIntersectionQuery("location", shape)) .setQuery(geoIntersectionQuery("location", shape))
@ -138,7 +141,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
.endObject() .endObject()
.endObject()).setRefresh(true).execute().actionGet(); .endObject()).setRefresh(true).execute().actionGet();
ShapeBuilder query = ShapeBuilders.newEnvelope().topLeft(-122.88, 48.62).bottomRight(-122.82, 48.54); ShapeBuilder query = ShapeBuilders.newEnvelope(new Coordinate(-122.88, 48.62), new Coordinate(-122.82, 48.54));
// This search would fail if both geoshape indexing and geoshape filtering // This search would fail if both geoshape indexing and geoshape filtering
// used the bottom-level optimization in SpatialPrefixTree#recursiveGetNodes. // used the bottom-level optimization in SpatialPrefixTree#recursiveGetNodes.
@ -163,7 +166,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
createIndex("shapes"); createIndex("shapes");
ensureGreen(); ensureGreen();
ShapeBuilder shape = ShapeBuilders.newEnvelope().topLeft(-45, 45).bottomRight(45, -45); ShapeBuilder shape = ShapeBuilders.newEnvelope(new Coordinate(-45, 45), new Coordinate(45, -45));
client().prepareIndex("shapes", "shape_type", "Big_Rectangle").setSource(jsonBuilder().startObject() client().prepareIndex("shapes", "shape_type", "Big_Rectangle").setSource(jsonBuilder().startObject()
.field("shape", shape).endObject()).setRefresh(true).execute().actionGet(); .field("shape", shape).endObject()).setRefresh(true).execute().actionGet();
@ -195,14 +198,13 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
} }
public void testReusableBuilder() throws IOException { public void testReusableBuilder() throws IOException {
ShapeBuilder polygon = ShapeBuilders.newPolygon() ShapeBuilder polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder()
.point(170, -10).point(190, -10).point(190, 10).point(170, 10) .coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close())
.hole(new LineStringBuilder().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close()) .hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, -5).coordinate(185, -5).coordinate(185, 5).coordinate(175, 5).close()));
.close();
assertUnmodified(polygon); assertUnmodified(polygon);
ShapeBuilder linestring = ShapeBuilders.newLineString() ShapeBuilder linestring = ShapeBuilders.newLineString(new CoordinatesBuilder()
.point(170, -10).point(190, -10).point(190, 10).point(170, 10); .coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close());
assertUnmodified(linestring); assertUnmodified(linestring);
} }
@ -327,7 +329,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
client().prepareIndex("test", "type", "1").setSource(docSource).setRefresh(true).execute().actionGet(); client().prepareIndex("test", "type", "1").setSource(docSource).setRefresh(true).execute().actionGet();
// index the mbr of the collection // index the mbr of the collection
EnvelopeBuilder env = new EnvelopeBuilder().topLeft(mbr.getMinX(), mbr.getMaxY()).bottomRight(mbr.getMaxX(), mbr.getMinY()); EnvelopeBuilder env = new EnvelopeBuilder(new Coordinate(mbr.getMinX(), mbr.getMaxY()), new Coordinate(mbr.getMaxX(), mbr.getMinY()));
docSource = env.toXContent(jsonBuilder().startObject().field("location"), null).endObject(); docSource = env.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
client().prepareIndex("test", "type", "2").setSource(docSource).setRefresh(true).execute().actionGet(); client().prepareIndex("test", "type", "2").setSource(docSource).setRefresh(true).execute().actionGet();
@ -375,8 +377,8 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
"location", "location",
ShapeBuilders.newGeometryCollection() ShapeBuilders.newGeometryCollection()
.polygon( .polygon(
ShapeBuilders.newPolygon().point(99.0, -1.0).point(99.0, 3.0).point(103.0, 3.0).point(103.0, -1.0) ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(99.0, -1.0).coordinate(99.0, 3.0).coordinate(103.0, 3.0).coordinate(103.0, -1.0)
.point(99.0, -1.0))).relation(ShapeRelation.INTERSECTS); .coordinate(99.0, -1.0)))).relation(ShapeRelation.INTERSECTS);
SearchResponse result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery()) SearchResponse result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
.setPostFilter(filter).get(); .setPostFilter(filter).get();
assertSearchResponse(result); assertSearchResponse(result);
@ -384,17 +386,17 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
filter = QueryBuilders.geoShapeQuery( filter = QueryBuilders.geoShapeQuery(
"location", "location",
ShapeBuilders.newGeometryCollection().polygon( ShapeBuilders.newGeometryCollection().polygon(
ShapeBuilders.newPolygon().point(199.0, -11.0).point(199.0, 13.0).point(193.0, 13.0).point(193.0, -11.0) ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(199.0, -11.0).coordinate(199.0, 13.0).coordinate(193.0, 13.0).coordinate(193.0, -11.0)
.point(199.0, -11.0))).relation(ShapeRelation.INTERSECTS); .coordinate(199.0, -11.0)))).relation(ShapeRelation.INTERSECTS);
result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery()) result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
.setPostFilter(filter).get(); .setPostFilter(filter).get();
assertSearchResponse(result); assertSearchResponse(result);
assertHitCount(result, 0); assertHitCount(result, 0);
filter = QueryBuilders.geoShapeQuery("location", ShapeBuilders.newGeometryCollection() filter = QueryBuilders.geoShapeQuery("location", ShapeBuilders.newGeometryCollection()
.polygon(ShapeBuilders.newPolygon().point(99.0, -1.0).point(99.0, 3.0).point(103.0, 3.0).point(103.0, -1.0).point(99.0, -1.0)) .polygon(ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(99.0, -1.0).coordinate(99.0, 3.0).coordinate(103.0, 3.0).coordinate(103.0, -1.0).coordinate(99.0, -1.0)))
.polygon( .polygon(
ShapeBuilders.newPolygon().point(199.0, -11.0).point(199.0, 13.0).point(193.0, 13.0).point(193.0, -11.0) ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(199.0, -11.0).coordinate(199.0, 13.0).coordinate(193.0, 13.0).coordinate(193.0, -11.0)
.point(199.0, -11.0))).relation(ShapeRelation.INTERSECTS); .coordinate(199.0, -11.0)))).relation(ShapeRelation.INTERSECTS);
result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery()) result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
.setPostFilter(filter).get(); .setPostFilter(filter).get();
assertSearchResponse(result); assertSearchResponse(result);

View File

@ -2549,6 +2549,43 @@ public class HighlighterSearchIT extends ESIntegTestCase {
} }
} }
public void testDoesNotHighlightTypeName() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("typename").startObject("properties")
.startObject("foo").field("type", "string")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").addMapping("typename", mapping));
ensureGreen();
indexRandom(true, client().prepareIndex("test", "typename").setSource("foo", "test typename"));
for (String highlighter: new String[] {"plain", "fvh", "postings"}) {
SearchResponse response = client().prepareSearch("test").setTypes("typename").setQuery(matchQuery("foo", "test"))
.highlighter(new HighlightBuilder().field("foo").highlighterType(highlighter).requireFieldMatch(false)).get();
assertHighlight(response, 0, "foo", 0, 1, equalTo("<em>test</em> typename"));
}
}
public void testDoesNotHighlightAliasFilters() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("typename").startObject("properties")
.startObject("foo").field("type", "string")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").addMapping("typename", mapping));
assertAcked(client().admin().indices().prepareAliases().addAlias("test", "filtered_alias", matchQuery("foo", "japanese")));
ensureGreen();
indexRandom(true, client().prepareIndex("test", "typename").setSource("foo", "test japanese"));
for (String highlighter: new String[] {"plain", "fvh", "postings"}) {
SearchResponse response = client().prepareSearch("filtered_alias").setTypes("typename").setQuery(matchQuery("foo", "test"))
.highlighter(new HighlightBuilder().field("foo").highlighterType(highlighter).requireFieldMatch(false)).get();
assertHighlight(response, 0, "foo", 0, 1, equalTo("<em>test</em> japanese"));
}
}
@AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore") @AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore")
public void testFastVectorHighlighterPhraseBoost() throws Exception { public void testFastVectorHighlighterPhraseBoost() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));

View File

@ -29,13 +29,15 @@ import com.spatial4j.core.shape.impl.Range;
import com.vividsolutions.jts.algorithm.ConvexHull; import com.vividsolutions.jts.algorithm.ConvexHull;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.geo.builders.CoordinateCollection;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder; import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
import org.elasticsearch.common.geo.builders.LineStringBuilder; import org.elasticsearch.common.geo.builders.LineStringBuilder;
import org.elasticsearch.common.geo.builders.MultiLineStringBuilder; import org.elasticsearch.common.geo.builders.MultiLineStringBuilder;
import org.elasticsearch.common.geo.builders.MultiPointBuilder; import org.elasticsearch.common.geo.builders.MultiPointBuilder;
import org.elasticsearch.common.geo.builders.PointBuilder; import org.elasticsearch.common.geo.builders.PointBuilder;
import org.elasticsearch.common.geo.builders.PointCollection;
import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.builders.PolygonBuilder;
import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.search.geo.GeoShapeQueryTests; import org.elasticsearch.search.geo.GeoShapeQueryTests;
@ -187,11 +189,12 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
// if this number gets out of hand, the number of self intersections for a linestring can become // if this number gets out of hand, the number of self intersections for a linestring can become
// (n^2-n)/2 and computing the relation intersection matrix will become NP-Hard // (n^2-n)/2 and computing the relation intersection matrix will become NP-Hard
int numPoints = RandomInts.randomIntBetween(r, 3, 10); int numPoints = RandomInts.randomIntBetween(r, 3, 10);
PointCollection pcb = (st == ShapeType.MULTIPOINT) ? new MultiPointBuilder() : new LineStringBuilder(); CoordinatesBuilder coordinatesBuilder = new CoordinatesBuilder();
for (int i=0; i<numPoints; ++i) { for (int i=0; i<numPoints; ++i) {
p = xRandomPointIn(r, within); p = xRandomPointIn(r, within);
pcb.point(p.getX(), p.getY()); coordinatesBuilder.coordinate(p.getX(), p.getY());
} }
CoordinateCollection pcb = (st == ShapeType.MULTIPOINT) ? new MultiPointBuilder(coordinatesBuilder.build()) : new LineStringBuilder(coordinatesBuilder);
return pcb; return pcb;
case MULTILINESTRING: case MULTILINESTRING:
MultiLineStringBuilder mlsb = new MultiLineStringBuilder(); MultiLineStringBuilder mlsb = new MultiLineStringBuilder();
@ -219,7 +222,7 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
shellCoords[2] = new Coordinate(within.getMaxX(), within.getMaxY()); shellCoords[2] = new Coordinate(within.getMaxX(), within.getMaxY());
shellCoords[3] = new Coordinate(within.getMaxX(), within.getMinY()); shellCoords[3] = new Coordinate(within.getMaxX(), within.getMinY());
} }
PolygonBuilder pgb = new PolygonBuilder().points(shellCoords).close(); PolygonBuilder pgb = new PolygonBuilder(new CoordinatesBuilder().coordinates(shellCoords).close());
if (validate) { if (validate) {
// This test framework builds semi-random geometry (in the sense that points are not truly random due to spatial // This test framework builds semi-random geometry (in the sense that points are not truly random due to spatial
// auto-correlation) As a result of the semi-random nature of the geometry, one can not predict the orientation // auto-correlation) As a result of the semi-random nature of the geometry, one can not predict the orientation

View File

@ -105,7 +105,7 @@ public class SimpleValidateQueryIT extends ESIntegTestCase {
} }
for (Client client : internalCluster()) { for (Client client : internalCluster()) {
ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test") ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test")
.setQuery(QueryBuilders.queryStringQuery("foo")) .setQuery(QueryBuilders.queryStringQuery("foo"))
.setExplain(true) .setExplain(true)
.execute().actionGet(); .execute().actionGet();

View File

@ -15,6 +15,7 @@ wiki1 1 p STARTED 3013 29.6mb 192.168.56.30 Frankie Raye
wiki1 2 p STARTED 3973 38.1mb 192.168.56.20 Commander Kraken wiki1 2 p STARTED 3973 38.1mb 192.168.56.20 Commander Kraken
-------------------------------------------------- --------------------------------------------------
[float]
[[index-pattern]] [[index-pattern]]
=== Index pattern === Index pattern
@ -31,6 +32,7 @@ wiki2 2 p STARTED 275 7.8mb 192.168.56.20 Commander Kraken
-------------------------------------------------- --------------------------------------------------
[float]
[[relocation]] [[relocation]]
=== Relocation === Relocation
@ -46,6 +48,7 @@ wiki1 0 r RELOCATING 3014 31.1mb 192.168.56.20 Commander Kraken -> 192.168.56.30
wiki1 1 r RELOCATING 3013 29.6mb 192.168.56.10 Stiletto -> 192.168.56.30 Frankie Raye wiki1 1 r RELOCATING 3013 29.6mb 192.168.56.10 Stiletto -> 192.168.56.30 Frankie Raye
-------------------------------------------------- --------------------------------------------------
[float]
[[states]] [[states]]
=== Shard states === Shard states
@ -66,8 +69,8 @@ wiki1 2 p STARTED 3973 38.1mb 192.168.56.20 Commander Kraken
-------------------------------------------------- --------------------------------------------------
If a shard cannot be assigned, for example you've overallocated the If a shard cannot be assigned, for example you've overallocated the
number of replicas for the number of nodes in the cluster, they will number of replicas for the number of nodes in the cluster, the shard
remain `UNASSIGNED`. will remain `UNASSIGNED` with the <<reason-unassigned,reason code>> `ALLOCATION_FAILED`.
[source,sh] [source,sh]
-------------------------------------------------- --------------------------------------------------
@ -78,13 +81,33 @@ remain `UNASSIGNED`.
wiki1 0 p STARTED 3014 31.1mb 192.168.56.10 Stiletto wiki1 0 p STARTED 3014 31.1mb 192.168.56.10 Stiletto
wiki1 0 r STARTED 3014 31.1mb 192.168.56.30 Frankie Raye wiki1 0 r STARTED 3014 31.1mb 192.168.56.30 Frankie Raye
wiki1 0 r STARTED 3014 31.1mb 192.168.56.20 Commander Kraken wiki1 0 r STARTED 3014 31.1mb 192.168.56.20 Commander Kraken
wiki1 0 r UNASSIGNED wiki1 0 r UNASSIGNED ALLOCATION_FAILED
wiki1 1 r STARTED 3013 29.6mb 192.168.56.10 Stiletto wiki1 1 r STARTED 3013 29.6mb 192.168.56.10 Stiletto
wiki1 1 p STARTED 3013 29.6mb 192.168.56.30 Frankie Raye wiki1 1 p STARTED 3013 29.6mb 192.168.56.30 Frankie Raye
wiki1 1 r STARTED 3013 29.6mb 192.168.56.20 Commander Kraken wiki1 1 r STARTED 3013 29.6mb 192.168.56.20 Commander Kraken
wiki1 1 r UNASSIGNED wiki1 1 r UNASSIGNED ALLOCATION_FAILED
wiki1 2 r STARTED 3973 38.1mb 192.168.56.10 Stiletto wiki1 2 r STARTED 3973 38.1mb 192.168.56.10 Stiletto
wiki1 2 r STARTED 3973 38.1mb 192.168.56.30 Frankie Raye wiki1 2 r STARTED 3973 38.1mb 192.168.56.30 Frankie Raye
wiki1 2 p STARTED 3973 38.1mb 192.168.56.20 Commander Kraken wiki1 2 p STARTED 3973 38.1mb 192.168.56.20 Commander Kraken
wiki1 2 r UNASSIGNED wiki1 2 r UNASSIGNED ALLOCATION_FAILED
-------------------------------------------------- --------------------------------------------------
[float]
[[reason-unassigned]]
=== Reasons for unassigned shard
These are the possible reasons for a shard be in a unassigned state:
[horizontal]
`INDEX_CREATED`:: Unassigned as a result of an API creation of an index.
`CLUSTER_RECOVERED`:: Unassigned as a result of a full cluster recovery.
`INDEX_REOPENED`:: Unassigned as a result of opening a closed index.
`DANGLING_INDEX_IMPORTED`:: Unassigned as a result of importing a dangling index.
`NEW_INDEX_RESTORED`:: Unassigned as a result of restoring into a new index.
`EXISTING_INDEX_RESTORED`:: Unassigned as a result of restoring into a closed index.
`REPLICA_ADDED`:: Unassigned as a result of explicit addition of a replica.
`ALLOCATION_FAILED`:: Unassigned as a result of a failed allocation of the shard.
`NODE_LEFT`:: Unassigned as a result of the node hosting it leaving the cluster.
`REROUTE_CANCELLED`:: Unassigned as a result of explicit cancel reroute command.
`REINITIALIZED`:: When a shard moves from started back to initializing, for example, with shadow replicas.
`REALLOCATED_REPLICA`:: A better replica location is identified and causes the existing replica allocation to be cancelled.

View File

@ -250,3 +250,36 @@ PUT my_index/my_type/1
<1> The `english` field is mapped as a `string` field with the `english` analyzer. <1> The `english` field is mapped as a `string` field with the `english` analyzer.
<2> The `count` field is mapped as a `long` field with `doc_values` disabled <2> The `count` field is mapped as a `long` field with `doc_values` disabled
[[override-default-template]]
=== Override default template
You can override the default mappings for all indices and all types
by specifying a `_default_` type mapping in an index template
which matches all indices.
For example, to disable the `_all` field by default for all types in all
new indices, you could create the following index template:
[source,js]
--------------------------------------------------
PUT _template/disable_all_field
{
"disable_all_field": {
"order": 0,
"template": "*", <1>
"mappings": {
"_default_": { <2>
"_all": { <3>
"enabled": false
}
}
}
}
}
--------------------------------------------------
// AUTOSENSE
<1> Applies the mappings to an `index` which matches the pattern `*`, in other
words, all new indices.
<2> Defines the `_default_` type mapping types within the index.
<3> Disables the `_all` field by default.

View File

@ -150,6 +150,10 @@ Removed support for the deprecated top level `filter` in the search api, replace
Removed support for the undocumented `query_binary` and `filter_binary` sections of a search request. Removed support for the undocumented `query_binary` and `filter_binary` sections of a search request.
==== `span_near`'s' `collect_payloads` deprecated
Payloads are now loaded when needed.
[[breaking_30_parent_child_changes]] [[breaking_30_parent_child_changes]]
=== Parent/Child changes === Parent/Child changes

View File

@ -77,9 +77,8 @@ supported scripting languages:
|groovy |no |built-in |groovy |no |built-in
|expression |yes |built-in |expression |yes |built-in
|mustache |yes |built-in |mustache |yes |built-in
|mvel |no |https://github.com/elastic/elasticsearch-lang-mvel[elasticsearch-lang-mvel] |javascript |no |{plugins}/lang-javascript.html[elasticsearch-lang-javascript]
|javascript |no |https://github.com/elastic/elasticsearch-lang-javascript[elasticsearch-lang-javascript] |python |no |{plugins}/lang-python.html[elasticsearch-lang-python]
|python |no |https://github.com/elastic/elasticsearch-lang-python[elasticsearch-lang-python]
|======================================================================= |=======================================================================
To increase security, Elasticsearch does not allow you to specify scripts for To increase security, Elasticsearch does not allow you to specify scripts for

View File

@ -16,8 +16,7 @@ matches are required to be in-order. The span near query maps to Lucene
{ "span_term" : { "field" : "value3" } } { "span_term" : { "field" : "value3" } }
], ],
"slop" : 12, "slop" : 12,
"in_order" : false, "in_order" : false
"collect_payloads" : false
} }
} }
-------------------------------------------------- --------------------------------------------------

View File

@ -56,7 +56,7 @@ dependencyLicenses {
mapping from: /jaxb-.*/, to: 'jaxb' mapping from: /jaxb-.*/, to: 'jaxb'
} }
compileJava.options.compilerArgs << '-Xlint:-path,-serial,-unchecked' compileJava.options.compilerArgs << '-Xlint:-path,-unchecked'
thirdPartyAudit.excludes = [ thirdPartyAudit.excludes = [
// classes are missing // classes are missing

View File

@ -31,7 +31,6 @@ import java.util.List;
* *
*/ */
public class NativeList extends NativeJavaObject implements Scriptable, Wrapper { public class NativeList extends NativeJavaObject implements Scriptable, Wrapper {
private static final long serialVersionUID = 3664761893203964569L;
private static final String LENGTH_PROPERTY = "length"; private static final String LENGTH_PROPERTY = "length";
private final List<Object> list; private final List<Object> list;

View File

@ -19,20 +19,18 @@
package org.elasticsearch.script.javascript.support; package org.elasticsearch.script.javascript.support;
import java.util.Iterator;
import java.util.Map;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Wrapper; import org.mozilla.javascript.Wrapper;
import java.util.Iterator;
import java.util.Map;
/** /**
* Wrapper for exposing maps in Rhino scripts. * Wrapper for exposing maps in Rhino scripts.
* *
* *
*/ */
public class NativeMap implements Scriptable, Wrapper { public class NativeMap implements Scriptable, Wrapper {
private static final long serialVersionUID = 3664761893203964569L;
private Map<Object, Object> map; private Map<Object, Object> map;
private Scriptable parentScope; private Scriptable parentScope;
private Scriptable prototype; private Scriptable prototype;

View File

@ -19,12 +19,12 @@
package org.elasticsearch.script.javascript.support; package org.elasticsearch.script.javascript.support;
import org.mozilla.javascript.Scriptable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.mozilla.javascript.Scriptable;
/** /**
* Implementation of a Scriptable Map. This is the best choice for maps that want to represent * Implementation of a Scriptable Map. This is the best choice for maps that want to represent
* JavaScript associative arrays - allowing access via key and integer index. It maintains and * JavaScript associative arrays - allowing access via key and integer index. It maintains and
@ -33,8 +33,6 @@ import org.mozilla.javascript.Scriptable;
* *
*/ */
public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements ScriptableMap<K, V> { public class ScriptableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements ScriptableMap<K, V> {
private static final long serialVersionUID = 3774167893214964123L;
private Scriptable parentScope; private Scriptable parentScope;
private Scriptable prototype; private Scriptable prototype;

View File

@ -35,5 +35,3 @@ dependencyLicenses {
mapping from: /stax-.*/, to: 'stax' mapping from: /stax-.*/, to: 'stax'
} }
compileJava.options.compilerArgs << '-Xlint:-serial'

View File

@ -33,7 +33,7 @@ dependencies {
compile 'org.elasticsearch:securemock:1.2' compile 'org.elasticsearch:securemock:1.2'
} }
compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-serial,-try,-unchecked' compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-try,-unchecked'
compileTestJava.options.compilerArgs << '-Xlint:-rawtypes' compileTestJava.options.compilerArgs << '-Xlint:-rawtypes'
// the main files are actually test files, so use the appopriate forbidden api sigs // the main files are actually test files, so use the appopriate forbidden api sigs

View File

@ -66,6 +66,19 @@ public class CapturingTransport implements Transport {
return capturedRequests.toArray(new CapturedRequest[0]); return capturedRequests.toArray(new CapturedRequest[0]);
} }
/**
* Returns all requests captured so far. This method does clear the
* captured requests list. If you do not want the captured requests
* list cleared, use {@link #capturedRequests()}.
*
* @return the captured requests
*/
public CapturedRequest[] getCapturedRequestsAndClear() {
CapturedRequest[] capturedRequests = capturedRequests();
clear();
return capturedRequests;
}
/** /**
* returns all requests captured so far, grouped by target node. * returns all requests captured so far, grouped by target node.
* Doesn't clear the captured request list. See {@link #clear()} * Doesn't clear the captured request list. See {@link #clear()}
@ -83,6 +96,20 @@ public class CapturingTransport implements Transport {
return map; return map;
} }
/**
* Returns all requests captured so far, grouped by target node.
* This method does clear the captured request list. If you do not
* want the captured requests list cleared, use
* {@link #capturedRequestsByTargetNode()}.
*
* @return the captured requests grouped by target node
*/
public Map<String, List<CapturedRequest>> getCapturedRequestsByTargetNodeAndClear() {
Map<String, List<CapturedRequest>> map = capturedRequestsByTargetNode();
clear();
return map;
}
/** clears captured requests */ /** clears captured requests */
public void clear() { public void clear() {
capturedRequests.clear(); capturedRequests.clear();