DATAES-46 - Apply code formatting
This commit is contained in:
@@ -113,21 +113,20 @@ class CriteriaFilterProcessor {
|
||||
Assert.isTrue(valArray[0] instanceof GeoPoint || valArray[0] instanceof String || valArray[0] instanceof Point, "First element of a geo distance filter must be a GeoPoint, a Point or a String");
|
||||
Assert.isTrue(valArray[1] instanceof String || valArray[1] instanceof Distance, "Second element of a geo distance filter must be a String or a Distance");
|
||||
|
||||
|
||||
StringBuilder dist = new StringBuilder();
|
||||
|
||||
if(valArray[1] instanceof Distance) {
|
||||
extractDistanceString((Distance)valArray[1], dist);
|
||||
} else {
|
||||
dist.append((String) valArray[1]);
|
||||
}
|
||||
|
||||
if (valArray[0] instanceof GeoPoint) {
|
||||
GeoPoint loc = (GeoPoint) valArray[0];
|
||||
((GeoDistanceFilterBuilder) filter).lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString());
|
||||
} else if (valArray[0] instanceof Point) {
|
||||
GeoPoint loc = GeoPoint.fromPoint((Point)valArray[0]);
|
||||
((GeoDistanceFilterBuilder) filter).lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString());
|
||||
if (valArray[1] instanceof Distance) {
|
||||
extractDistanceString((Distance) valArray[1], dist);
|
||||
} else {
|
||||
dist.append((String) valArray[1]);
|
||||
}
|
||||
|
||||
if (valArray[0] instanceof GeoPoint) {
|
||||
GeoPoint loc = (GeoPoint) valArray[0];
|
||||
((GeoDistanceFilterBuilder) filter).lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString());
|
||||
} else if (valArray[0] instanceof Point) {
|
||||
GeoPoint loc = GeoPoint.fromPoint((Point) valArray[0]);
|
||||
((GeoDistanceFilterBuilder) filter).lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString());
|
||||
} else {
|
||||
String loc = (String) valArray[0];
|
||||
if (loc.contains(",")) {
|
||||
@@ -167,40 +166,40 @@ class CriteriaFilterProcessor {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* extract the distance string from a {@link org.springframework.data.geo.Distance} object.
|
||||
*
|
||||
* @param distance distance object to extract string from
|
||||
* @param sb StringBuilder to build the distance string
|
||||
*/
|
||||
private void extractDistanceString(Distance distance, StringBuilder sb) {
|
||||
// handle Distance object
|
||||
sb.append((int) distance.getValue());
|
||||
/**
|
||||
* extract the distance string from a {@link org.springframework.data.geo.Distance} object.
|
||||
*
|
||||
* @param distance distance object to extract string from
|
||||
* @param sb StringBuilder to build the distance string
|
||||
*/
|
||||
private void extractDistanceString(Distance distance, StringBuilder sb) {
|
||||
// handle Distance object
|
||||
sb.append((int) distance.getValue());
|
||||
|
||||
Metrics metric = (Metrics) distance.getMetric();
|
||||
Metrics metric = (Metrics) distance.getMetric();
|
||||
|
||||
switch (metric) {
|
||||
case KILOMETERS :
|
||||
sb.append("km");
|
||||
break;
|
||||
case MILES:
|
||||
sb.append("mi");
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (metric) {
|
||||
case KILOMETERS:
|
||||
sb.append("km");
|
||||
break;
|
||||
case MILES:
|
||||
sb.append("mi");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void oneParameterBBox(GeoBoundingBoxFilterBuilder filter, Object value) {
|
||||
private void oneParameterBBox(GeoBoundingBoxFilterBuilder filter, Object value) {
|
||||
Assert.isTrue(value instanceof GeoBox || value instanceof Box, "single-element of boundedBy filter must be type of GeoBox or Box");
|
||||
|
||||
GeoBox geoBBox;
|
||||
if(value instanceof Box) {
|
||||
Box sdbox = (Box) value;
|
||||
geoBBox = GeoBox.fromBox(sdbox);
|
||||
} else {
|
||||
geoBBox = (GeoBox) value;
|
||||
}
|
||||
if (value instanceof Box) {
|
||||
Box sdbox = (Box) value;
|
||||
geoBBox = GeoBox.fromBox(sdbox);
|
||||
} else {
|
||||
geoBBox = (GeoBox) value;
|
||||
}
|
||||
|
||||
filter.topLeft(geoBBox.getTopLeft().getLat(), geoBBox.getTopLeft().getLon());
|
||||
filter.topLeft(geoBBox.getTopLeft().getLat(), geoBBox.getTopLeft().getLon());
|
||||
filter.bottomRight(geoBBox.getBottomRight().getLat(), geoBBox.getBottomRight().getLon());
|
||||
}
|
||||
|
||||
|
||||
@@ -473,5 +473,5 @@ public interface ElasticsearchOperations {
|
||||
Set<String> queryForAlias(String indexName);
|
||||
|
||||
|
||||
<T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor);
|
||||
<T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
Assert.notNull(type, "No type defined for putMapping()");
|
||||
Map mappings = null;
|
||||
try {
|
||||
mappings = client.admin().indices().getMappings(new GetMappingsRequest().indices(indexName).types(type))
|
||||
mappings = client.admin().indices().getMappings(new GetMappingsRequest().indices(indexName).types(type))
|
||||
.actionGet().getMappings().get(indexName).get(type).getSourceAsMap();
|
||||
} catch (Exception e) {
|
||||
throw new ElasticsearchException("Error while getting mapping for indexName : " + indexName + " type : " + type + " " + e.getMessage());
|
||||
@@ -248,13 +248,13 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
return mapper.mapResults(response, clazz, query.getPageable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor) {
|
||||
SearchResponse response = doSearch(prepareSearch(query), query);
|
||||
return resultsExtractor.extract(response);
|
||||
}
|
||||
@Override
|
||||
public <T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor) {
|
||||
SearchResponse response = doSearch(prepareSearch(query), query);
|
||||
return resultsExtractor.extract(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public <T> List<T> queryForList(CriteriaQuery query, Class<T> clazz) {
|
||||
return queryForPage(query, clazz).getContent();
|
||||
}
|
||||
@@ -417,7 +417,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
}
|
||||
throw new ElasticsearchException(
|
||||
"Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages ["
|
||||
+ failedDocuments + "]", failedDocuments);
|
||||
+ failedDocuments + "]", failedDocuments
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,7 +502,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
requestBuilder.setPostFilter(searchQuery.getFilter());
|
||||
}
|
||||
|
||||
if(isNotEmpty(searchQuery.getFields())) {
|
||||
if (isNotEmpty(searchQuery.getFields())) {
|
||||
requestBuilder.addFields(toArray(searchQuery.getFields()));
|
||||
}
|
||||
|
||||
@@ -615,11 +616,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
}
|
||||
}
|
||||
|
||||
if(CollectionUtils.isNotEmpty(searchQuery.getAggregations())){
|
||||
for(AbstractAggregationBuilder aggregationBuilder : searchQuery.getAggregations()){
|
||||
searchRequest.addAggregation(aggregationBuilder);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(searchQuery.getAggregations())) {
|
||||
for (AbstractAggregationBuilder aggregationBuilder : searchQuery.getAggregations()) {
|
||||
searchRequest.addAggregation(aggregationBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
return searchRequest.setQuery(searchQuery.getQuery()).execute().actionGet();
|
||||
}
|
||||
@@ -906,7 +907,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
if (bufferedReader != null)
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
logger.debug(String.format("Unable to close buffered reader.. %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
||||
public interface ResultsExtractor<T> {
|
||||
T extract(SearchResponse response);
|
||||
public interface ResultsExtractor<T> {
|
||||
T extract(SearchResponse response);
|
||||
}
|
||||
|
||||
@@ -40,17 +40,17 @@ public class GeoBox {
|
||||
return bottomRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a {@link org.springframework.data.elasticsearch.core.geo.GeoBox}
|
||||
* from a {@link org.springframework.data.geo.Box}.
|
||||
*
|
||||
* @param box {@link org.springframework.data.geo.Box} to use
|
||||
* @return a {@link org.springframework.data.elasticsearch.core.geo.GeoBox}
|
||||
*/
|
||||
public static GeoBox fromBox(Box box) {
|
||||
GeoPoint topLeft = GeoPoint.fromPoint(box.getFirst());
|
||||
GeoPoint bottomRight = GeoPoint.fromPoint(box.getSecond());
|
||||
/**
|
||||
* return a {@link org.springframework.data.elasticsearch.core.geo.GeoBox}
|
||||
* from a {@link org.springframework.data.geo.Box}.
|
||||
*
|
||||
* @param box {@link org.springframework.data.geo.Box} to use
|
||||
* @return a {@link org.springframework.data.elasticsearch.core.geo.GeoBox}
|
||||
*/
|
||||
public static GeoBox fromBox(Box box) {
|
||||
GeoPoint topLeft = GeoPoint.fromPoint(box.getFirst());
|
||||
GeoPoint bottomRight = GeoPoint.fromPoint(box.getSecond());
|
||||
|
||||
return new GeoBox(topLeft, bottomRight);
|
||||
}
|
||||
return new GeoBox(topLeft, bottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ public class GeoPoint {
|
||||
return lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* build a GeoPoint from a {@link org.springframework.data.geo.Point}
|
||||
*
|
||||
* @param point {@link org.springframework.data.geo.Point}
|
||||
* @return a {@link org.springframework.data.elasticsearch.core.geo.GeoPoint}
|
||||
*/
|
||||
public static GeoPoint fromPoint(Point point) {
|
||||
return new GeoPoint(point.getY(), point.getX());
|
||||
}
|
||||
/**
|
||||
* build a GeoPoint from a {@link org.springframework.data.geo.Point}
|
||||
*
|
||||
* @param point {@link org.springframework.data.geo.Point}
|
||||
* @return a {@link org.springframework.data.elasticsearch.core.geo.GeoPoint}
|
||||
*/
|
||||
public static GeoPoint fromPoint(Point point) {
|
||||
return new GeoPoint(point.getY(), point.getX());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -362,20 +362,20 @@ public class Criteria {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new CriteriaEntry for {@code location WITHIN distance}
|
||||
*
|
||||
* @param location {@link org.springframework.data.geo.Point} center coordinates
|
||||
* @param distance {@link org.springframework.data.geo.Distance} radius
|
||||
* .
|
||||
* @return Criteria the chaind criteria with the new 'within' criteria included.
|
||||
*/
|
||||
public Criteria within(Point location, Distance distance) {
|
||||
Assert.notNull(location, "Location value for near criteria must not be null");
|
||||
Assert.notNull(location, "Distance value for near criteria must not be null");
|
||||
filterCriteria.add(new CriteriaEntry(OperationKey.WITHIN, new Object[]{location, distance}));
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Creates new CriteriaEntry for {@code location WITHIN distance}
|
||||
*
|
||||
* @param location {@link org.springframework.data.geo.Point} center coordinates
|
||||
* @param distance {@link org.springframework.data.geo.Distance} radius
|
||||
* .
|
||||
* @return Criteria the chaind criteria with the new 'within' criteria included.
|
||||
*/
|
||||
public Criteria within(Point location, Distance distance) {
|
||||
Assert.notNull(location, "Location value for near criteria must not be null");
|
||||
Assert.notNull(location, "Distance value for near criteria must not be null");
|
||||
filterCriteria.add(new CriteriaEntry(OperationKey.WITHIN, new Object[]{location, distance}));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new CriteriaEntry for {@code geoLocation WITHIN distance}
|
||||
@@ -408,7 +408,6 @@ public class Criteria {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates new CriteriaEntry for bounding box created from points
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||
private FilterBuilder filter;
|
||||
private List<SortBuilder> sorts;
|
||||
private List<FacetRequest> facets;
|
||||
private List<AbstractAggregationBuilder> aggregations;
|
||||
private List<AbstractAggregationBuilder> aggregations;
|
||||
private HighlightBuilder.Field[] highlightFields;
|
||||
|
||||
|
||||
@@ -97,20 +97,20 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||
return facets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractAggregationBuilder> getAggregations() {
|
||||
return aggregations;
|
||||
}
|
||||
@Override
|
||||
public List<AbstractAggregationBuilder> getAggregations() {
|
||||
return aggregations;
|
||||
}
|
||||
|
||||
|
||||
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||
if (aggregations == null) {
|
||||
aggregations = new ArrayList<AbstractAggregationBuilder>();
|
||||
}
|
||||
aggregations.add(aggregationBuilder);
|
||||
}
|
||||
public void addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||
if (aggregations == null) {
|
||||
aggregations = new ArrayList<AbstractAggregationBuilder>();
|
||||
}
|
||||
aggregations.add(aggregationBuilder);
|
||||
}
|
||||
|
||||
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
||||
this.aggregations = aggregations;
|
||||
}
|
||||
public void setAggregations(List<AbstractAggregationBuilder> aggregations) {
|
||||
this.aggregations = aggregations;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class NativeSearchQueryBuilder {
|
||||
private FilterBuilder filterBuilder;
|
||||
private List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
||||
private List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
|
||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
||||
private HighlightBuilder.Field[] highlightFields;
|
||||
private Pageable pageable;
|
||||
private String[] indices;
|
||||
@@ -69,10 +69,10 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder){
|
||||
this.aggregationBuilders.add(aggregationBuilder);
|
||||
return this;
|
||||
}
|
||||
public NativeSearchQueryBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
|
||||
this.aggregationBuilders.add(aggregationBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
||||
facetRequests.add(facetRequest);
|
||||
@@ -146,9 +146,9 @@ public class NativeSearchQueryBuilder {
|
||||
nativeSearchQuery.setFacets(facetRequests);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(aggregationBuilders)) {
|
||||
nativeSearchQuery.setAggregations(aggregationBuilders);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(aggregationBuilders)) {
|
||||
nativeSearchQuery.setAggregations(aggregationBuilders);
|
||||
}
|
||||
|
||||
if (minScore > 0) {
|
||||
nativeSearchQuery.setMinScore(minScore);
|
||||
|
||||
@@ -135,6 +135,7 @@ public interface Query {
|
||||
|
||||
/**
|
||||
* Type of search
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
SearchType getSearchType();
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface SearchQuery extends Query {
|
||||
|
||||
List<FacetRequest> getFacets();
|
||||
|
||||
List<AbstractAggregationBuilder> getAggregations();
|
||||
List<AbstractAggregationBuilder> getAggregations();
|
||||
|
||||
HighlightBuilder.Field[] getHighlightFields();
|
||||
}
|
||||
|
||||
@@ -126,43 +126,42 @@ public class ElasticsearchQueryCreator extends AbstractQueryCreator<CriteriaQuer
|
||||
return criteria.in(asArray(parameters.next()));
|
||||
case NOT_IN:
|
||||
return criteria.in(asArray(parameters.next())).not();
|
||||
case WITHIN: {
|
||||
Object firstParameter = parameters.next();
|
||||
Object secondParameter = parameters.next();
|
||||
case WITHIN: {
|
||||
Object firstParameter = parameters.next();
|
||||
Object secondParameter = parameters.next();
|
||||
|
||||
if(firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||
return criteria.within((GeoPoint)firstParameter, (String)secondParameter);
|
||||
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
||||
|
||||
if(firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||
return criteria.within((Point)firstParameter, (Distance)secondParameter);
|
||||
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
||||
|
||||
if (firstParameter instanceof String && secondParameter instanceof String)
|
||||
return criteria.within((String) firstParameter, (String) secondParameter);
|
||||
}
|
||||
case NEAR: {
|
||||
Object firstParameter = parameters.next();
|
||||
|
||||
if(firstParameter instanceof String && secondParameter instanceof String)
|
||||
return criteria.within((String)firstParameter, (String)secondParameter);
|
||||
}
|
||||
case NEAR : {
|
||||
Object firstParameter = parameters.next();
|
||||
if (firstParameter instanceof GeoBox) {
|
||||
return criteria.boundedBy((GeoBox) firstParameter);
|
||||
}
|
||||
|
||||
if(firstParameter instanceof GeoBox) {
|
||||
return criteria.boundedBy((GeoBox)firstParameter);
|
||||
}
|
||||
if (firstParameter instanceof Box) {
|
||||
return criteria.boundedBy(GeoBox.fromBox((Box) firstParameter));
|
||||
}
|
||||
|
||||
if(firstParameter instanceof Box) {
|
||||
return criteria.boundedBy(GeoBox.fromBox((Box) firstParameter));
|
||||
}
|
||||
Object secondParameter = parameters.next();
|
||||
|
||||
Object secondParameter = parameters.next();
|
||||
// "near" query can be the same query as the "within" query
|
||||
if (firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||
return criteria.within((GeoPoint) firstParameter, (String) secondParameter);
|
||||
|
||||
// "near" query can be the same query as the "within" query
|
||||
if(firstParameter instanceof GeoPoint && secondParameter instanceof String)
|
||||
return criteria.within((GeoPoint)firstParameter, (String)secondParameter);
|
||||
if (firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||
return criteria.within((Point) firstParameter, (Distance) secondParameter);
|
||||
|
||||
if(firstParameter instanceof Point && secondParameter instanceof Distance)
|
||||
return criteria.within((Point)firstParameter, (Distance)secondParameter);
|
||||
|
||||
if(firstParameter instanceof String && secondParameter instanceof String)
|
||||
return criteria.within((String)firstParameter, (String)secondParameter);
|
||||
}
|
||||
if (firstParameter instanceof String && secondParameter instanceof String)
|
||||
return criteria.within((String) firstParameter, (String) secondParameter);
|
||||
}
|
||||
|
||||
default:
|
||||
throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
|
||||
|
||||
Reference in New Issue
Block a user