From e63c06d28e1c965dff334d0f98e30cd08ce98529 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 21 Oct 2017 16:11:56 +0200 Subject: [PATCH] fixing search --- Handler/Search.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Handler/Search.hs b/Handler/Search.hs index cc0da3d..db1a727 100755 --- a/Handler/Search.hs +++ b/Handler/Search.hs @@ -20,6 +20,7 @@ import Import import qualified Data.Text as T import Data.Maybe (fromJust) +import Data.List (sortBy) import Database.Persist.Sql (rawSql) @@ -31,11 +32,15 @@ getSearchR = do searchForm case res of FormSuccess query -> do - mediumList <- runDB $ (++) - rawSql "select ?? from medium where any(string_to_array(title, ' ') % ?" + mediumList <- runDB $ do + a <- rawSql "select ?? from medium where any(string_to_array(title, ' ') % ?" [PersistText query] - rawSql "select ?? from medium where any(string_to_array(description, ' ') % ?" + b <- rawSql "select ?? from medium where any(string_to_array(description, ' ') % ?" [PersistText query] + return $ sortBy (\ sa sb -> compare + (T.unpack $ mediumTitle $ entityVal sa) + (T.unpack $ mediumTitle $ entityVal sb)) + $ a ++ b userList <- runDB $ rawSql "select ?? from \"user\" where name % ?" [PersistText query] albumList <- runDB $