Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Fix for hashtag filter
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed Oct 19, 2023
1 parent 9c91368 commit 8642b75
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/dbapi/api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def tagsQueryFilter(tagsQuery, table):
query += "OR {0}.tags->>'{1}' IS NOT NULL".format(table, keyValue[0])
return query

def hashtagQueryFilter(hashtag, table):
return table + ".changeset IN (SELECT c.id FROM changesets c where jsonb_path_exists(to_jsonb(hashtags), '$[*] ? (@ like_regex \"^{0}\")') GROUP BY C.id)".format(hashtag)

def getGeoType(table):
if table == "ways_poly":
return "Polygon"
Expand Down Expand Up @@ -71,7 +74,7 @@ def geoFeaturesQuery(
as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, table) + ")" if tags else "",
"AND " + table + ".changeset IN (SELECT c.id FROM changesets c where jsonb_path_exists(to_jsonb(hashtags), '$[*] ? (@ like_regex \"^{0}\")') GROUP BY C.id)".format(hashtag) if hashtag else "",
"AND " + hashtagQueryFilter(hashtag, table) if hashtag else "",
"AND created at >= {0} AND created_at <= {1}".format(dateFrom, dateTo) if dateFrom and dateTo else "",
"LIMIT " + str(RESULTS_PER_PAGE),
)
Expand Down Expand Up @@ -103,7 +106,7 @@ def listFeaturesQuery(
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, table) + ")" if tags else "",
"AND " + table + ".changeset IN (SELECT c.id FROM changesets c where jsonb_path_exists(to_jsonb(hashtags), '$[*] ? (@ like_regex \"^{0}\")') GROUP BY C.id)".format(hashtag) if hashtag else "",
"AND " + hashtagQueryFilter(hashtag, table) if hashtag else "",
"AND created_at >= '{0}' AND created_at <= '{1}'".format(dateFrom, dateTo) if (dateFrom and dateTo) else "",
"AND created_at IS NOT NULL ORDER BY created_at DESC LIMIT " + str(RESULTS_PER_PAGE_LIST) + (" OFFSET {0}".format(page * RESULTS_PER_PAGE_LIST) if page else ""),
)
Expand Down

0 comments on commit 8642b75

Please sign in to comment.