Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bookbrainz-search: Change the reindex script to just message the sear…

…ch queue

Instead of actually doing work, this script just pushes all known BBIDs into the
message queue, and lets the daemon deal with it.
  • Loading branch information...
commit b6ceea90e522014b126edd78f5024e73256c642e 1 parent 2e0aaff
Oliver Charles authored
View
4 bookbrainz-search/bookbrainz-search.cabal
@@ -45,10 +45,10 @@ Executable bookbrainz-search-reindex
main-is: Main.hs
Build-depends:
+ amqp >= 0.3.1 && < 0.4,
base >= 4.5 && < 5,
bookbrainz-data ==0.1,
- bookbrainz-search,
- elasticsearch >= 0.1 && < 0.2,
+ bytestring >= 0.9.2.1 && < 0.10,
transformers >= 0.3.0.0 && < 0.4
if impl(ghc >= 6.12.0)
View
33 bookbrainz-search/reindex/Main.hs
@@ -1,18 +1,33 @@
module Main where
+import qualified Data.ByteString.Lazy.Char8 as LBS
+import Control.Monad.IO.Class (liftIO)
+import Network.AMQP
+
import BookBrainz.Model.Book
import BookBrainz.Model.Edition
import BookBrainz.Model.Person
import BookBrainz.Model.Publisher
import BookBrainz.Script
-import BookBrainz.Search
-
-reindexEverything :: Script ()
-reindexEverything = do
- listAllBooks >>= mapM_ indexBook
- listAllEditions >>= mapM_ indexEdition
- allPersons >>= mapM_ indexPerson
- allPublishers >>= mapM_ indexPublisher
+import BookBrainz.Types
main :: IO ()
-main = runScript reindexEverything
+main = runScript $ do
+ chan <- liftIO $
+ openConnection "127.0.0.1" "/" "guest" "guest" >>= openChannel
+
+ mapM_ (dispatch chan) types
+
+ where
+ types = [ (bbids listAllBooks ,"book")
+ , (bbids allEditions, "edition")
+ , (bbids allPersons, "person")
+ , (bbids allPublishers, "publisher")
+ ]
+ publish chan t bbid' = publishMsg chan "search" t
+ newMsg { msgBody = LBS.pack bbid'
+ , msgDeliveryMode = Just Persistent
+ }
+ dispatch chan (lister, queue) =
+ lister >>= liftIO . mapM_ (publish chan queue)
+ bbids = fmap (map (show . bbid))
Please sign in to comment.
Something went wrong with that request. Please try again.