Skip to content

Commit

Permalink
one query string for all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jorpic committed Apr 13, 2012
1 parent 6069dec commit 2e00b71
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/Snap/Snaplet/Redson.hs
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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) ())]
Expand Down

1 comment on commit 2e00b71

@dzhus
Copy link
Member

@dzhus dzhus commented on 2e00b71 Apr 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не очень понятно, зачем эти изменения?

Please sign in to comment.