Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

one query string for all fields

  • Loading branch information...
commit 2e00b711b8812816993c2c776448de037714c430 1 parent 6069dec
@jorpic jorpic authored
Showing with 8 additions and 11 deletions.
  1. +8 −11 src/Snap/Snaplet/Redson.hs
View
19 src/Snap/Snaplet/Redson.hs
@@ -17,6 +17,7 @@ module Snap.Snaplet.Redson
where
+import qualified Prelude (id)
import Prelude hiding (concat, FilePath, id)
import Control.Monad.State hiding (put)
@@ -423,20 +424,14 @@ search =
itemLimit <- fromIntParam "_limit" defaultSearchLimit
+ query <- fromMaybe "" <$> getParam "q"
-- Produce Just SearchTerm
- indexValues <- mapM (\(i, c) -> do
- p <- getParam i
- case p of
- Nothing -> return Nothing
- Just s -> if c then return $
- Just (i, CRUD.collate s)
- else return $
- Just (i, s))
- (indices m)
+ let collate c = if c then CRUD.collate else Prelude.id
+ let indexValues = map (mapSnd (`collate` query)) $ indices m
-- For every term, get list of ids which match it
termIds <- runRedisDB database $
- redisSearch m (catMaybes indexValues) patFunction
+ redisSearch m indexValues patFunction
modifyResponse $ setContentType "application/json"
case (filter (not . null) termIds) of
@@ -454,9 +449,11 @@ search =
[] -> writeLBS $ A.encode instances
_ -> writeLBS $ A.encode $
map (flip CRUD.onlyFields outFields) instances
- return ()
+mapSnd :: (b -> c) -> (a, b) -> (a, c)
+mapSnd f (a, b) = (a, f b)
+
-----------------------------------------------------------------------------
-- | CRUD routes for models.
routes :: [(B.ByteString, Handler b (Redson b) ())]

0 comments on commit 2e00b71

Please sign in to comment.
Something went wrong with that request. Please try again.