search term in filter for food items

This commit is contained in:
Bart Akeley 2018-06-03 12:25:33 -05:00
parent e1e98a297a
commit 422aacbe34
4 changed files with 23 additions and 12 deletions

View file

@ -1,5 +1,6 @@
CREATE EXTENSION IF NOT EXISTS "postgis";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "fuzzystrmatch";
DROP TYPE IF EXISTS QUANTITY CASCADE;
CREATE TYPE QUANTITY AS ENUM ('lots', 'many', 'few', 'none');
DROP TYPE IF EXISTS CATEGORY CASCADE;

View file

@ -49,12 +49,16 @@
(defn wrap-in-quotes [token]
(str/replace token #"(^|$)" "'"))
(defn wildcard
[term]
(str "%" (str/join (interpose "%" term)) "%"))
(defn get-where [{:keys [:lat :lng :filter]}]
(let [radius (or (:radius filter) 10)
categories (:categories filter)]
(cond
categories (has-category {:categories (map wrap-in-quotes categories) :lat lat :lng lng :dist radius})
:else (within-radius {:lat lat :lng lng :dist radius}))))
(food-items-where-clause {:lat lat
:lng lng
:dist (:radius filter)
:categories (map wrap-in-quotes (:categories filter))
:search (wildcard (:search filter))}))
(defn query-food-items [{lat :lat lng :lng filter :filter}]
(select-food-items
@ -72,12 +76,12 @@
(defn create-food-item [{:keys [:name :placeId :category :quantity :latitude :longitude]}]
(let [food-item (first (insert-food-item
@pooled-db
{:name name
:placeId placeId
:category category
:longitude longitude
:latitude latitude}))
@pooled-db
{:name name
:placeId placeId
:category category
:longitude longitude
:latitude latitude}))
quantity (first (insert-quantity {:foodItemId (:id food-item) :quantity quantity}))]
(merge food-item (select-keys quantity [:quantity :date]))))

View file

@ -33,7 +33,7 @@
(fn [map]
(update map key build-s3-url)))
([key map]
(update map key build-s3-url)))
(update map key build-s3-url)))
(defn food-items-handler

View file

@ -24,6 +24,12 @@ category IN (:i*:categories)
-- :snip within-radius
WHERE ST_DWithin(loc, ST_SetSRID(ST_Point(:lng, :lat), 4326)::geography, :dist * 1609)
-- :snip food-items-where-clause
WHERE
ST_DWithin(loc, ST_SetSRID(ST_Point(:lng, :lat), 4326)::geography, :dist * 1609)
--~ (when (seq (:categories params)) "AND category IN (:i*:categories)")
--~ (when (not-empty (:search params)) "AND name like :v:search")
-- :snip by-distance
ORDER BY distance ASC