-- eidolon -- A simple gallery in Haskell and Yesod -- Copyright (C) 2015 Amedeo Molnár -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as published -- by the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU Affero General Public License for more details. -- -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . module Handler.Search where import Import import qualified Data.Text as T import Data.Maybe (fromJust) import Database.Persist.Sql (rawSql) import System.FilePath (splitDirectories) getSearchR :: Handler Html getSearchR = do ((res, widget), _) <- runFormGet $ renderBootstrap3 BootstrapBasicForm $ searchForm case res of FormSuccess query -> do mediumList <- runDB $ rawSql "select ?? from medium where title % ?" [PersistText query] userList <- runDB $ rawSql "select ?? from \"user\" where name % ?" [PersistText query] albumList <- runDB $ rawSql "select ?? from album where title % ?" [PersistText query] let allEmpty = null mediumList && null userList && null albumList defaultLayout $ do setTitle $ toHtml $ "Eidolon :: Search results for " ++ (T.unpack query) $(widgetFile "result") _ -> defaultLayout $ do setTitle "Eidolon :: Search" $(widgetFile "search") searchForm :: AForm Handler T.Text searchForm = areq (searchField True) "Search" Nothing