Skip to content

Commit

Permalink
Merge pull request #519 from lonvia/remove-unused-interfaces
Browse files Browse the repository at this point in the history
Remove more unused interface classes
  • Loading branch information
lonvia authored Dec 23, 2020
2 parents 28b5068 + 045aead commit 92c08d3
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 331 deletions.
56 changes: 18 additions & 38 deletions src/main/java/de/komoot/photon/query/PhotonQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
* </ul>
* <p/>
* Created by Sachin Dole on 2/12/2015.
*
* @see de.komoot.photon.query.TagFilterQueryBuilder
*/
public class PhotonQueryBuilder implements TagFilterQueryBuilder {
public class PhotonQueryBuilder {
private FunctionScoreQueryBuilder m_finalQueryWithoutTagFilterBuilder;

private BoolQueryBuilder m_queryBuilderForTopLevelFilter;
Expand Down Expand Up @@ -102,14 +100,13 @@ private PhotonQueryBuilder(String query, String language) {
*
* @param query the value for photon query parameter "q"
* @param language
* @return An initialized {@link TagFilterQueryBuilder photon query builder}.
* @return An initialized {@link PhotonQueryBuilder photon query builder}.
*/
public static TagFilterQueryBuilder builder(String query, String language) {
public static PhotonQueryBuilder builder(String query, String language) {
return new PhotonQueryBuilder(query, language);
}

@Override
public TagFilterQueryBuilder withLocationBias(Point point, double scale) {
public PhotonQueryBuilder withLocationBias(Point point, double scale) {
if (point == null) return this;
Map<String, Object> params = newHashMap();
params.put("lon", point.getX());
Expand All @@ -127,17 +124,15 @@ public TagFilterQueryBuilder withLocationBias(Point point, double scale) {
return this;
}

@Override
public TagFilterQueryBuilder withBoundingBox(Envelope bbox) {
public PhotonQueryBuilder withBoundingBox(Envelope bbox) {
if (bbox == null) return this;
bboxQueryBuilder = new GeoBoundingBoxQueryBuilder("coordinate");
bboxQueryBuilder.setCorners(bbox.getMaxY(), bbox.getMinX(), bbox.getMinY(), bbox.getMaxX());

return this;
}

@Override
public TagFilterQueryBuilder withTags(Map<String, Set<String>> tags) {
public PhotonQueryBuilder withTags(Map<String, Set<String>> tags) {
if (!checkTags(tags)) return this;

ensureFiltered();
Expand All @@ -155,8 +150,7 @@ public TagFilterQueryBuilder withTags(Map<String, Set<String>> tags) {
}


@Override
public TagFilterQueryBuilder withKeys(Set<String> keys) {
public PhotonQueryBuilder withKeys(Set<String> keys) {
if (!checkTags(keys)) return this;

ensureFiltered();
Expand All @@ -168,8 +162,7 @@ public TagFilterQueryBuilder withKeys(Set<String> keys) {
}


@Override
public TagFilterQueryBuilder withValues(Set<String> values) {
public PhotonQueryBuilder withValues(Set<String> values) {
if (!checkTags(values)) return this;

ensureFiltered();
Expand All @@ -181,8 +174,7 @@ public TagFilterQueryBuilder withValues(Set<String> values) {
}


@Override
public TagFilterQueryBuilder withTagsNotValues(Map<String, Set<String>> tags) {
public PhotonQueryBuilder withTagsNotValues(Map<String, Set<String>> tags) {
if (!checkTags(tags)) return this;

ensureFiltered();
Expand All @@ -202,8 +194,7 @@ public TagFilterQueryBuilder withTagsNotValues(Map<String, Set<String>> tags) {
}


@Override
public TagFilterQueryBuilder withoutTags(Map<String, Set<String>> tagsToExclude) {
public PhotonQueryBuilder withoutTags(Map<String, Set<String>> tagsToExclude) {
if (!checkTags(tagsToExclude)) return this;

ensureFiltered();
Expand All @@ -225,8 +216,7 @@ public TagFilterQueryBuilder withoutTags(Map<String, Set<String>> tagsToExclude)
}


@Override
public TagFilterQueryBuilder withoutKeys(Set<String> keysToExclude) {
public PhotonQueryBuilder withoutKeys(Set<String> keysToExclude) {
if (!checkTags(keysToExclude)) return this;

ensureFiltered();
Expand All @@ -241,8 +231,7 @@ public TagFilterQueryBuilder withoutKeys(Set<String> keysToExclude) {
}


@Override
public TagFilterQueryBuilder withoutValues(Set<String> valuesToExclude) {
public PhotonQueryBuilder withoutValues(Set<String> valuesToExclude) {
if (!checkTags(valuesToExclude)) return this;

ensureFiltered();
Expand All @@ -257,40 +246,34 @@ public TagFilterQueryBuilder withoutValues(Set<String> valuesToExclude) {
}


@Override
public TagFilterQueryBuilder withKeys(String... keys) {
public PhotonQueryBuilder withKeys(String... keys) {
return this.withKeys(ImmutableSet.<String>builder().add(keys).build());
}


@Override
public TagFilterQueryBuilder withValues(String... values) {
public PhotonQueryBuilder withValues(String... values) {
return this.withValues(ImmutableSet.<String>builder().add(values).build());
}


@Override
public TagFilterQueryBuilder withoutKeys(String... keysToExclude) {
public PhotonQueryBuilder withoutKeys(String... keysToExclude) {
return this.withoutKeys(ImmutableSet.<String>builder().add(keysToExclude).build());
}


@Override
public TagFilterQueryBuilder withoutValues(String... valuesToExclude) {
public PhotonQueryBuilder withoutValues(String... valuesToExclude) {
return this.withoutValues(ImmutableSet.<String>builder().add(valuesToExclude).build());
}


@Override
public TagFilterQueryBuilder withStrictMatch() {
public PhotonQueryBuilder withStrictMatch() {
defaultMatchQueryBuilder.minimumShouldMatch("100%");
languageMatchQueryBuilder.minimumShouldMatch("100%");
return this;
}


@Override
public TagFilterQueryBuilder withLenientMatch() {
public PhotonQueryBuilder withLenientMatch() {
defaultMatchQueryBuilder.fuzziness(Fuzziness.ONE).minimumShouldMatch("-1");
languageMatchQueryBuilder.fuzziness(Fuzziness.ONE).minimumShouldMatch("-1");
return this;
Expand All @@ -301,10 +284,7 @@ public TagFilterQueryBuilder withLenientMatch() {
* When this method is called, all filters are placed inside their {@link OrQueryBuilder OR} or {@link AndQueryBuilder AND} containers and the top level filter
* builder is built. Subsequent invocations of this method have no additional effect. Note that after this method is called, calling other methods on this class also
* have no effect.
*
* @see TagFilterQueryBuilder#buildQuery()
*/
@Override
public QueryBuilder buildQuery() {
if (state.equals(State.FINISHED)) return m_finalQueryBuilder;

Expand Down
99 changes: 2 additions & 97 deletions src/main/java/de/komoot/photon/query/ReverseQueryBuilder.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package de.komoot.photon.query;

import com.google.common.collect.ImmutableSet;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Point;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.Map;
import java.util.Set;

/**
* @author svantulden
*/
public class ReverseQueryBuilder implements TagFilterQueryBuilder {
public class ReverseQueryBuilder {
private Double radius;

private Point location;

private String queryStringFilter;

private ReverseQueryBuilder(Point location, Double radius, String queryStringFilter) {
Expand All @@ -27,86 +20,10 @@ private ReverseQueryBuilder(Point location, Double radius, String queryStringFil
this.queryStringFilter = queryStringFilter;
}

public static TagFilterQueryBuilder builder(Point location, Double radius, String queryStringFilter) {
public static ReverseQueryBuilder builder(Point location, Double radius, String queryStringFilter) {
return new ReverseQueryBuilder(location, radius, queryStringFilter);
}

@Override
public TagFilterQueryBuilder withLocationBias(Point point, double scale) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withBoundingBox(Envelope bbox) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withTags(Map<String, Set<String>> tags) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withKeys(Set<String> keys) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withValues(Set<String> values) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withTagsNotValues(Map<String, Set<String>> tags) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withoutTags(Map<String, Set<String>> tagsToExclude) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withoutKeys(Set<String> keysToExclude) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withoutValues(Set<String> valuesToExclude) {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withKeys(String... keys) {
return this.withKeys(ImmutableSet.<String>builder().add(keys).build());
}

@Override
public TagFilterQueryBuilder withValues(String... values) {
return this.withValues(ImmutableSet.<String>builder().add(values).build());
}

@Override
public TagFilterQueryBuilder withoutKeys(String... keysToExclude) {
return this.withoutKeys(ImmutableSet.<String>builder().add(keysToExclude).build());
}

@Override
public TagFilterQueryBuilder withoutValues(String... valuesToExclude) {
return this.withoutValues(ImmutableSet.<String>builder().add(valuesToExclude).build());
}

@Override
public TagFilterQueryBuilder withStrictMatch() {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public TagFilterQueryBuilder withLenientMatch() {
throw new RuntimeException(new NoSuchMethodException("this method is not implemented (NOOP)"));
}

@Override
public QueryBuilder buildQuery() {
QueryBuilder fb = QueryBuilders.geoDistanceQuery("coordinate").point(location.getY(), location.getX())
.distance(radius, DistanceUnit.KILOMETERS);
Expand All @@ -120,16 +37,4 @@ public QueryBuilder buildQuery() {

return finalQuery;
}

private Boolean checkTags(Set<String> keys) {
return !(keys == null || keys.isEmpty());
}

private Boolean checkTags(Map<String, Set<String>> tags) {
return !(tags == null || tags.isEmpty());
}

private enum State {
PLAIN, FILTERED, QUERY_ALREADY_BUILT, FINISHED,
}
}
Loading

0 comments on commit 92c08d3

Please sign in to comment.