Skip to content

Commit

Permalink
#3043: Add geosearch query for locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ysf-simsoft committed Jul 24, 2020
1 parent aa51f0f commit e840813
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/mil/dds/anet/beans/search/LocationSearchQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class LocationSearchQuery extends AbstractSearchQuery<LocationSearchSortB
@GraphQLInputField
private LocationStatus status;

@GraphQLQuery
@GraphQLInputField
private String withinPolygon;

public LocationSearchQuery() {
super(LocationSearchSortBy.NAME);
}
Expand All @@ -22,4 +26,12 @@ public void setStatus(LocationStatus status) {
this.status = status;
}

public String getWithinPolygon() {
return withinPolygon;
}

public void setWithinPolygon(String withinPolygon) {
this.withinPolygon = withinPolygon;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ protected void buildQuery(LocationSearchQuery query) {
qb.addSqlArg("userUuid", DaoUtils.getUuid(query.getUser()));
}

if (query.getWithinPolygon() != null) {
addWithinPolygon(query);
}

addOrderByClauses(qb, query);
}

protected abstract void addTextQuery(LocationSearchQuery query);

protected abstract void addWithinPolygon(LocationSearchQuery query);

protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
switch (query.getSortBy()) {
case CREATED_AT:
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/mil/dds/anet/search/AbstractSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ protected void addFullTextSearch(String tableName, String text, boolean isSortBy
}
}

protected void addWithinPolygonMssql(String locationUuidColumn, String queryText) {
qb.addWhereClause(String.format(
"\"%1$s\" IN (SELECT \"uuid\" FROM locations WHERE \"geometry\".STWithin(geometry::STGeomFromText('%2$s', 3857)) = 1)",
locationUuidColumn, queryText));
}

protected void addWithinPolygonPsql(String locationUuidColumn, String queryText) {
qb.addWhereClause(String.format(
"\"%1$s\" IN (SELECT \"uuid\" FROM locations WHERE ST_Within(\"geometry\", ST_GeomFromText('%2$s', 3857)))",
locationUuidColumn, queryText));
}

protected List<String> getOrderBy(SortOrder sortOrder, String table, String... columns) {
final List<String> clauses = new ArrayList<>();
for (final String column : columns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ protected void addTextQuery(LocationSearchQuery query) {
qb.addSqlArg("containsQuery", qb.getContainsQuery(text));
}

@Override
protected void addWithinPolygon(LocationSearchQuery query) {
addWithinPolygonMssql("uuid", query.getWithinPolygon());
}

@Override
protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
if (query.isTextPresent() && !query.isSortByPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ protected void addTextQuery(LocationSearchQuery query) {
addFullTextSearch("locations", query.getText(), query.isSortByPresent());
}

@Override
protected void addWithinPolygon(LocationSearchQuery query) {
addWithinPolygonPsql("uuid", query.getWithinPolygon());
}

@Override
protected void addOrderByClauses(AbstractSearchQueryBuilder<?, ?> qb, LocationSearchQuery query) {
if (query.isTextPresent() && !query.isSortByPresent()) {
Expand Down

0 comments on commit e840813

Please sign in to comment.