From 63342563fb5a23369c7664918a95e42ed30a7967 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 12 Jul 2016 18:46:45 +0200 Subject: [PATCH] search index now repopulatable --- Handler/Admin.hs | 21 +++++++++++++++++++++ config/routes | 1 + templates/adminBase.hamlet | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/Handler/Admin.hs b/Handler/Admin.hs index 1c0d5da..c70b585 100755 --- a/Handler/Admin.hs +++ b/Handler/Admin.hs @@ -18,6 +18,7 @@ module Handler.Admin where import Import import Handler.Commons +import Database.Bloodhound getAdminR :: Handler Html getAdminR = do @@ -30,3 +31,23 @@ getAdminR = do Left (errorMsg, route) -> do setMessage errorMsg redirect route + +getAdminSearchReloadR :: Handler Html +getAdminSearchReloadR = do + adminCheck <- loginIsAdmin + case adminCheck of + Right _ -> do + _ <- runBH' $ deleteIndex $ IndexName "_all" + users <- runDB $ selectList [] [Asc UserId] + albums <- runDB $ selectList [] [Asc AlbumId] + media <- runDB $ selectList [] [Asc MediumId] + comments <- runDB $ selectList [] [Asc CommentId] + mapM_ (\ u -> putIndexES $ ESUser (entityKey u) (entityVal u)) users + mapM_ (\ u -> putIndexES $ ESAlbum (entityKey u) (entityVal u)) albums + mapM_ (\ u -> putIndexES $ ESMedium (entityKey u) (entityVal u)) media + mapM_ (\ u -> putIndexES $ ESComment (entityKey u) (entityVal u)) comments + setMessage "search indices repopulated" + redirect AdminR + Left (msg, route) -> do + setMessage msg + redirect route diff --git a/config/routes b/config/routes index 0ff96f5..bda9f14 100755 --- a/config/routes +++ b/config/routes @@ -57,6 +57,7 @@ /admin/medium/#MediumId/delete AdminMediumDeleteR GET /admin/comment AdminCommentR GET /admin/comment/#CommentId AdminCommentDeleteR GET +/admin/repop-search AdminSearchReloadR GET /tag/#Text TagR GET diff --git a/templates/adminBase.hamlet b/templates/adminBase.hamlet index 6ee0f64..ab9fbb1 100755 --- a/templates/adminBase.hamlet +++ b/templates/adminBase.hamlet @@ -25,3 +25,8 @@ $newline always

Comments + +