From ba8db39c75d7de8054478927cf29489e90658f7c Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 17 Oct 2015 21:52:23 +0200 Subject: [PATCH] made elasticsearch parameters configurable --- Helper.hs | 22 +++++++++++++--------- Settings.hs | 10 ++++++++++ config/settings.yml | 8 ++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Helper.hs b/Helper.hs index 4be9fd3..afc18d0 100755 --- a/Helper.hs +++ b/Helper.hs @@ -209,13 +209,17 @@ multiFileField = Field , fieldEnctype = Multipart } --- Handler () +putIndexES :: ESInput -> Handler () putIndexES input = do + master <- getYesod + shards <- appShards $ appSettings master + replicas <- appReplicas $ appSettings master + let is = return $ IndexSettings (ShardCount shards) (ReplicaCount replicas) resp <- case input of ESUser uId user -> do ex <- runBH' $ indexExists (IndexName "user") when (not ex) ((\ _ -> do - runBH' $ createIndex singleIndexSettings (IndexName "user") + runBH' $ createIndex is (IndexName "user") return () ) ex) _ <- runBH' $ openIndex (IndexName "user") @@ -223,7 +227,7 @@ putIndexES input = do ESAlbum aId album -> do ex <- runBH' $ indexExists (IndexName "album") when (not ex) ((\ _ -> do - runBH' $ createIndex singleIndexSettings (IndexName "album") + runBH' $ createIndex is (IndexName "album") return () ) ex) _ <- runBH' $ openIndex (IndexName "album") @@ -231,7 +235,7 @@ putIndexES input = do ESMedium mId medium -> do ex <- runBH' $ indexExists (IndexName "medium") when (not ex) ((\ _ -> do - runBH' $ createIndex singleIndexSettings (IndexName "medium") + runBH' $ createIndex is (IndexName "medium") return () ) ex) _ <- runBH' $ openIndex (IndexName "medium") @@ -239,7 +243,7 @@ putIndexES input = do ESComment cId comment -> do ex <- runBH' $ indexExists (IndexName "comment") when (not ex) ((\ _ -> do - runBH' $ createIndex singleIndexSettings (IndexName "comment") + runBH' $ createIndex is (IndexName "comment") return () ) ex) _ <- runBH' $ openIndex (IndexName "comment") @@ -266,9 +270,9 @@ deleteIndexES input = do _ -> error $ C.unpack $ BL.toStrict $ responseBody resp runBH' action = do - let server = Server "http://localhost:9200" + master <- getYesod + server <- appSearchHost $ appSettings master + port <- return . show =<< (appSearchPort $ appSettings master) + let server = Server $ server ++ ":" ++ port manager <- newManager defaultManagerSettings runBH (BHEnv server manager) action - -singleIndexSettings :: IndexSettings -singleIndexSettings = IndexSettings (ShardCount 1) (ReplicaCount 1) diff --git a/Settings.hs b/Settings.hs index 18d52fa..9899aa0 100755 --- a/Settings.hs +++ b/Settings.hs @@ -75,6 +75,11 @@ data AppSettings = AppSettings , appTos1 :: Text , appTos2 :: Text -- ^ Terms of Service + , appSearchHost :: Text + , appSearchPort :: Text + , appShards :: Int + , appReplicas :: Int + -- ^ Settings for Elasticsearch } instance FromJSON AppSettings where @@ -106,6 +111,11 @@ instance FromJSON AppSettings where appTos1 <- o .: "tos1" appTos2 <- o .: "tos2" + appSearchHost <- o .: "searchhost" + appSearchPort <- o .: "searchport" + appShards <- o .: "shards" + appReplicas <- o .: "replicas" + return AppSettings {..} -- | Settings for 'widgetFile', such as which template languages to support and diff --git a/config/settings.yml b/config/settings.yml index 5f9a9fd..b80edab 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -47,5 +47,13 @@ copyrightLink: https://github.com/nek0/eidolon # block signup process signupBlocked: "_env:SIGNUP_BLOCK:false" + +# Terms of Service tos1: "Terms of Service 1" tos2: "Terms of Service 2" + +# Elasticsearcha settings +searchhost: "localhost" +searchport: 9200 +shards: 1 +replicas: 2