refined search and made it globally accessible
This commit is contained in:
parent
ee0ca0bf94
commit
77d6089588
7 changed files with 52 additions and 17 deletions
|
@ -94,6 +94,17 @@ renderLayout widget = do
|
|||
copyrightWidget <- widgetToPageContent $
|
||||
$(widgetFile "copyrightFooter")
|
||||
|
||||
searchWidget <- widgetToPageContent $ [whamlet|
|
||||
<form action=@{SearchR} method=GET>
|
||||
<input type="hidden" name="_hasdata">
|
||||
<div .required>
|
||||
<label for="hident2">
|
||||
<input #hident2 type="search" autofocus="" required="" name="f1">
|
||||
<script>
|
||||
if (!('autofocus' in document.createElement('input'))) {document.getElementById('hident2').focus();}
|
||||
<input value="Search" type="submit">
|
||||
|]
|
||||
|
||||
wc <- widgetToPageContent widget
|
||||
|
||||
pc <- widgetToPageContent $ do
|
||||
|
|
|
@ -7,6 +7,7 @@ import Data.Maybe
|
|||
import qualified Data.Text as T
|
||||
import Database.Bloodhound
|
||||
import Network.HTTP.Client (responseBody)
|
||||
import System.FilePath.Posix
|
||||
|
||||
getSearchR :: Handler Html
|
||||
getSearchR = do
|
||||
|
@ -14,11 +15,11 @@ getSearchR = do
|
|||
results <-
|
||||
case res of
|
||||
FormSuccess query -> do
|
||||
r <- getResults query
|
||||
a <- return $ (decode (responseBody r) :: Maybe (SearchResult SearchUser))
|
||||
b <- return $ (decode (responseBody r) :: Maybe (SearchResult SearchAlbum))
|
||||
c <- return $ (decode (responseBody r) :: Maybe (SearchResult SearchMedium))
|
||||
d <- return $ (decode (responseBody r) :: Maybe (SearchResult SearchComment))
|
||||
(ru, ra, rm, rc) <- getResults query
|
||||
a <- return $ (decode (responseBody ru) :: Maybe (SearchResult SearchUser))
|
||||
b <- return $ (decode (responseBody ra) :: Maybe (SearchResult SearchAlbum))
|
||||
c <- return $ (decode (responseBody rm) :: Maybe (SearchResult SearchMedium))
|
||||
d <- return $ (decode (responseBody rc) :: Maybe (SearchResult SearchComment))
|
||||
return $ Just (a, b, c, d)
|
||||
_ -> return $ Nothing
|
||||
case results of
|
||||
|
@ -85,9 +86,14 @@ getSearchR = do
|
|||
searchForm :: Form T.Text
|
||||
searchForm = renderDivs $ areq (searchField True) "Search" Nothing
|
||||
|
||||
getResults :: Text -> Handler (Reply, Reply, Reply, Reply)
|
||||
getResults query = do
|
||||
let esQuery = QuerySimpleQueryStringQuery (SimpleQueryStringQuery (QueryString query) Nothing Nothing Nothing Nothing Nothing Nothing)
|
||||
liftIO $ runBH' $ searchAll $ mkSearch (Just esQuery) Nothing
|
||||
su <- liftIO $ runBH' $ searchByIndex (IndexName "user") $ mkSearch (Just esQuery) Nothing
|
||||
sa <- liftIO $ runBH' $ searchByIndex (IndexName "album") $ mkSearch (Just esQuery) Nothing
|
||||
sm <- liftIO $ runBH' $ searchByIndex (IndexName "medium") $ mkSearch (Just esQuery) Nothing
|
||||
sc <- liftIO $ runBH' $ searchByIndex (IndexName "comment") $ mkSearch (Just esQuery) Nothing
|
||||
return (su, sa, sm, sc)
|
||||
|
||||
data SearchUser = SearchUser
|
||||
{ suName :: T.Text
|
||||
|
|
|
@ -262,7 +262,7 @@ deleteIndexES input = do
|
|||
runBH' $ deleteDocument (IndexName "comment") (MappingName "comment") (DocId $ extractKey cId)
|
||||
case statusCode (responseStatus resp) of
|
||||
201 -> return ()
|
||||
-- 200 -> return ()
|
||||
200 -> return ()
|
||||
_ -> error $ C.unpack $ BL.toStrict $ responseBody resp
|
||||
|
||||
runBH' action = do
|
||||
|
|
|
@ -219,11 +219,22 @@
|
|||
padding: 1em 2em;
|
||||
}
|
||||
|
||||
#user-nav
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
nav li
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#search
|
||||
{
|
||||
display: inline-block;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.comment
|
||||
{
|
||||
border: 5px solid rgb(255, 255, 255);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
$if block == False
|
||||
<li>
|
||||
<a href=@{SignupR}>Signup
|
||||
<div #search .right>
|
||||
^{pageBody searchWidget}
|
||||
|
||||
$maybe msg <- mmsg
|
||||
<div #message>#{msg}
|
||||
|
|
|
@ -18,7 +18,7 @@ $forall (Entity albumId album) <- userAlbs
|
|||
<a href=@{AlbumR albumId}>
|
||||
<figure class="thumbnail">
|
||||
$if (albumSamplePic album) == Nothing
|
||||
<img src=@{StaticR img_album_jpg}>
|
||||
<img src=@{StaticR img_album_jpg} title=#{albumTitle album}>
|
||||
$else
|
||||
<img src=@{StaticR $ StaticRoute (drop 2 $ map T.pack $ splitDirectories $ fromJust $ albumSamplePic album) []} title=#{albumTitle album}>
|
||||
<figcaption>#{albumTitle album}
|
||||
|
|
|
@ -26,20 +26,25 @@ $else
|
|||
<h1>
|
||||
Results in Albums:
|
||||
$forall (Entity aId album) <- albumList
|
||||
<div #header .item data-width="400">
|
||||
<div .inner>
|
||||
<article .item data-width="#{albumSampleWidth album}">
|
||||
<a href=@{AlbumR aId}>
|
||||
#{albumTitle album}
|
||||
<figure .thumbnail>
|
||||
$if (albumSamplePic album) == Nothing
|
||||
<img src=@{StaticR img_album_jpg} title=#{albumTitle album}>
|
||||
$else
|
||||
<img src=@{StaticR $ StaticRoute (drop 2 $ map T.pack $ splitDirectories $ fromJust $ albumSamplePic album) []} title=#{albumTitle album}>
|
||||
<figcaption>#{albumTitle album}
|
||||
$if not $ null mediumList
|
||||
<div #header .item data-width="400">
|
||||
<article #header .item data-width="400">
|
||||
<div .inner>
|
||||
<h1>
|
||||
Results in Media:
|
||||
$forall (Entity mId medium) <- mediumList
|
||||
<div #header .item data-width="400">
|
||||
<div .inner>
|
||||
<article .item data-width="#{mediumThumbWidth medium}">
|
||||
<a href=@{MediumR mId}>
|
||||
#{mediumTitle medium}
|
||||
<figure .thumbnail>
|
||||
<img src=@{StaticR $ StaticRoute (drop 2 $ map T.pack $ splitDirectories $ mediumThumb medium) []} title=#{mediumTitle medium}>
|
||||
<figcaption>#{mediumTitle medium}
|
||||
$if not $ null commentList
|
||||
<div #header .item data-width="400">
|
||||
<div .inner>
|
||||
|
|
Loading…
Reference in a new issue