Case Study: Sphinx-based Search

Sphinx is a search server, and powers the search feature on many sites. While the actual code necessary to integrate Yesod with Sphinx is relatively short, it touches on a number of complicated topics, and is therefore a great case study in how to play with some of the under-the-surface details of Yesod.

There are essentially three different pieces at play here:

  • Storing the content we wish to search. This is fairly straight-forward Persistent code, and we won’t dwell on it much in this chapter.

  • Accessing Sphinx search results from inside Yesod. Thanks to the sphinx package, this is actually very easy.

  • Providing the document content to Sphinx. This is where the interesting stuff happens, and will show how to deal with streaming content from a database directly to XML, which gets sent directly over the wire to the client.

The full code for this example can be found on FP Haskell Center.

Sphinx Setup

Unlike many of our other examples, to start with here we’ll need to actually configure and run our external Sphinx server. I’m not going to go into all the details of Sphinx, partly because it’s not relevant to our point here, and mostly because I’m not an expert on Sphinx.

Sphinx provides three main command line utilities: searchd is the actual search daemon that receives requests from the client (in this case, our web app) and returns the search results. indexer parses the set of documents and creates the search index. search is a debugging utility that will run simple queries against Sphinx.

There are two important settings: the source and the index. The source tells Sphinx where to read document information from. It has direct support for MySQL and PostgreSQL, as well as a more general XML format known as xmlpipe2. We’re going to use the last one. This not only will give us more flexibility with choosing Persistent backends, but will also demonstrate some more powerful Yesod concepts.

The second setting is the index. Sphinx can handle multiple indices simultaneously, which allows it to provide search for multiple services at once. Each index will have a source it pulls from.

In our case, we’re going to provide a URL from our application (/search/xmlpipe) that provides the XML file required by Sphinx, and then pipe that through to the indexer. So we’ll add the following to our Sphinx config file:

  1. source searcher_src
  2. {
  3. type = xmlpipe2
  4. xmlpipe_command = curl http://localhost:3000/search/xmlpipe
  5. }
  6. index searcher
  7. {
  8. source = searcher_src
  9. path = /var/data/searcher
  10. docinfo = extern
  11. charset_type = utf-8
  12. }
  13. searchd
  14. {
  15. listen = 9312
  16. pid_file = /var/run/sphinxsearch/searchd.pid
  17. }

In order to build your search index, you would run indexer searcher. Obviously this won’t work until you have your web app running. For a production site, it would make sense to run this command via a cron job so the index is regularly updated.

Basic Yesod Setup

Let’s get our basic Yesod setup going. We’re going to have a single table in the database for holding documents, which consist of a title and content. We’ll store this in a SQLite database, and provide routes for searching, adding documents, viewing documents and providing the xmlpipe file to Sphinx.

  1. share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
  2. Doc
  3. title Text
  4. content Textarea
  5. |]
  6. data Searcher = Searcher
  7. { connPool :: ConnectionPool
  8. }
  9. mkYesod "Searcher" [parseRoutes|
  10. / HomeR GET
  11. /doc/#DocId DocR GET
  12. /add-doc AddDocR POST
  13. /search SearchR GET
  14. /search/xmlpipe XmlpipeR GET
  15. |]
  16. instance Yesod Searcher
  17. instance YesodPersist Searcher where
  18. type YesodPersistBackend Searcher = SqlBackend
  19. runDB action = do
  20. Searcher pool <- getYesod
  21. runSqlPool action pool
  22. instance YesodPersistRunner Searcher where -- see below
  23. getDBRunner = defaultGetDBRunner connPool
  24. instance RenderMessage Searcher FormMessage where
  25. renderMessage _ _ = defaultFormMessage

Hopefully all of this looks pretty familiar by now. The one new thing we’ve defined here is an instance of YesodPersistRunner. This is a typeclass necessary for creating streaming database responses. The default implementation (defaultGetDBRunner) is almost always appropriate.

Next we’ll define some forms: one for creating documents, and one for searching:

  1. addDocForm :: Html -> MForm Handler (FormResult Doc, Widget)
  2. addDocForm = renderTable $ Doc
  3. <$> areq textField "Title" Nothing
  4. <*> areq textareaField "Contents" Nothing
  5. searchForm :: Html -> MForm Handler (FormResult Text, Widget)
  6. searchForm = renderDivs $ areq (searchField True) "Query" Nothing

The True parameter to searchField makes the field auto-focus on page load. Finally, we have some standard handlers for the homepage (shows the add document form and the search form), the document display, and adding a document.

  1. getHomeR :: Handler Html
  2. getHomeR = do
  3. docCount <- runDB $ count ([] :: [Filter Doc])
  4. ((_, docWidget), _) <- runFormPost addDocForm
  5. ((_, searchWidget), _) <- runFormGet searchForm
  6. let docs = if docCount == 1
  7. then "There is currently 1 document."
  8. else "There are currently " ++ show docCount ++ " documents."
  9. defaultLayout
  10. [whamlet|
  11. <p>Welcome to the search application. #{docs}
  12. <form method=post action=@{AddDocR}>
  13. <table>
  14. ^{docWidget}
  15. <tr>
  16. <td colspan=3>
  17. <input type=submit value="Add document">
  18. <form method=get action=@{SearchR}>
  19. ^{searchWidget}
  20. <input type=submit value=Search>
  21. |]
  22. postAddDocR :: Handler Html
  23. postAddDocR = do
  24. ((res, docWidget), _) <- runFormPost addDocForm
  25. case res of
  26. FormSuccess doc -> do
  27. docid <- runDB $ insert doc
  28. setMessage "Document added"
  29. redirect $ DocR docid
  30. _ -> defaultLayout
  31. [whamlet|
  32. <form method=post action=@{AddDocR}>
  33. <table>
  34. ^{docWidget}
  35. <tr>
  36. <td colspan=3>
  37. <input type=submit value="Add document">
  38. |]
  39. getDocR :: DocId -> Handler Html
  40. getDocR docid = do
  41. doc <- runDB $ get404 docid
  42. defaultLayout
  43. [whamlet|
  44. <h1>#{docTitle doc}
  45. <div .content>#{docContent doc}
  46. |]

Searching

Now that we’ve got the boring stuff out of the way, let’s jump into the actual searching. We’re going to need three pieces of information for displaying a result: the document ID it comes from, the title of that document, and the excerpts. Excerpts are the highlighted portions of the document which contain the search term.

Search Result

Case Study: Sphinx-based Search - 图1

So let’s start off by defining a Result datatype:

  1. data Result = Result
  2. { resultId :: DocId
  3. , resultTitle :: Text
  4. , resultExcerpt :: Html
  5. }

Next we’ll look at the search handler:

  1. getSearchR :: Handler Html
  2. getSearchR = do
  3. ((formRes, searchWidget), _) <- runFormGet searchForm
  4. searchResults <-
  5. case formRes of
  6. FormSuccess qstring -> getResults qstring
  7. _ -> return []
  8. defaultLayout $ do
  9. toWidget
  10. [lucius|
  11. .excerpt {
  12. color: green; font-style: italic
  13. }
  14. .match {
  15. background-color: yellow;
  16. }
  17. |]
  18. [whamlet|
  19. <form method=get action=@{SearchR}>
  20. ^{searchWidget}
  21. <input type=submit value=Search>
  22. $if not $ null searchResults
  23. <h1>Results
  24. $forall result <- searchResults
  25. <div .result>
  26. <a href=@{DocR $ resultId result}>#{resultTitle result}
  27. <div .excerpt>#{resultExcerpt result}
  28. |]

Nothing magical here, we’re just relying on the searchForm defined above, and the getResults function which hasn’t been defined yet. This function just takes a search string, and returns a list of results. This is where we first interact with the Sphinx API. We’ll be using two functions: query will return a list of matches, and buildExcerpts will return the highlighted excerpts. Let’s first look at getResults:

  1. getResults :: Text -> Handler [Result]
  2. getResults qstring = do
  3. sphinxRes' <- liftIO $ S.query config "searcher" qstring
  4. case sphinxRes' of
  5. ST.Ok sphinxRes -> do
  6. let docids = map (toSqlKey . ST.documentId) $ ST.matches sphinxRes
  7. fmap catMaybes $ runDB $ forM docids $ \docid -> do
  8. mdoc <- get docid
  9. case mdoc of
  10. Nothing -> return Nothing
  11. Just doc -> liftIO $ Just <$> getResult docid doc qstring
  12. _ -> error $ show sphinxRes'
  13. where
  14. config = S.defaultConfig
  15. { S.port = 9312
  16. , S.mode = ST.Any
  17. }

query takes three parameters: the configuration options, the index to search against (searcher in this case) and the search string. It returns a list of document IDs that contain the search string. The tricky bit here is that those documents are returned as Int64 values, whereas we need DocIds. Fortunately, for the SQL Persist backends, we can just use the toSqlKey function to perform the conversion.

If you’re dealing with a backend that has non-numeric IDs, like MongoDB, you’ll need to work out something a bit more clever than this.

We then loop over the resulting IDs to get a [Maybe Result] value, and use catMaybes to turn it into a [Result]. In the where clause, we define our local settings, which override the default port and set up the search to work when any term matches the document.

Let’s finally look at the getResult function:

  1. getResult :: DocId -> Doc -> Text -> IO Result
  2. getResult docid doc qstring = do
  3. excerpt' <- S.buildExcerpts
  4. excerptConfig
  5. [escape $ docContent doc]
  6. "searcher"
  7. qstring
  8. let excerpt =
  9. case excerpt' of
  10. ST.Ok texts -> preEscapedToHtml $ mconcat texts
  11. _ -> ""
  12. return Result
  13. { resultId = docid
  14. , resultTitle = docTitle doc
  15. , resultExcerpt = excerpt
  16. }
  17. where
  18. excerptConfig = E.altConfig { E.port = 9312 }
  19. escape :: Textarea -> Text
  20. escape =
  21. T.concatMap escapeChar . unTextarea
  22. where
  23. escapeChar '<' = "&lt;"
  24. escapeChar '>' = "&gt;"
  25. escapeChar '&' = "&amp;"
  26. escapeChar c = T.singleton c

buildExcerpts takes four parameters: the configuration options, the textual contents of the document, the search index and the search term. The interesting bit is that we entity escape the text content. Sphinx won’t automatically escape these for us, so we must do it explicitly.

Similarly, the result from Sphinx is a list of Texts. But of course, we’d rather have Html. So we concat that list into a single Text and use preEscapedToHtml to make sure that the tags inserted for matches are not escaped. A sample of this HTML is:

  1. &#8230; Departments. The President shall have <span class='match'>Power</span> to fill up all Vacancies
  2. &#8230; people. Amendment 11 The Judicial <span class='match'>power</span> of the United States shall
  3. &#8230; jurisdiction. 2. Congress shall have <span class='match'>power</span> to enforce this article by
  4. &#8230; 5. The Congress shall have <span class='match'>power</span> to enforce, by appropriate legislation
  5. &#8230;

Streaming xmlpipe output

We’ve saved the best for last. For the majority of Yesod handlers, the recommended approach is to load up the database results into memory and then produce the output document based on that. It’s simpler to work with, but more importantly it’s more resilient to exceptions. If there’s a problem loading the data from the database, the user will get a proper 500 response code.

What do I mean by “proper 500 response code?” If you start streaming a response to a client, and encounter an exception halfway through, there’s no way to change the status code; the user will see a 200 response that simply stops in the middle. Not only can this partial content be confusing, but it’s an invalid usage of the HTTP spec.

However, generating the xmlpipe output is a perfect example of the alternative. There are potentially a huge number of documents, and documents could easily be several hundred kilobytes. If we take a non-streaming approach, this can lead to huge memory usage and slow response times.

So how exactly do we create a streaming response? Yesod provides a helper function for this case: responseSourceDB. This function takes two arguments: a content type, and a conduit Source providing a stream of blaze-builder Builders. Yesod then handles all of the issues of grabbing a database connection from the connection pool, starting a transaction, and streaming the response to the user.

Now we know we want to create a stream of Builders from some XML content. Fortunately, the xml-conduit package provides this interface directly. xml-conduit provides some high-level interfaces for dealing with documents as a whole, but in our case, we’re going to need to use the low-level Event interface to ensure minimal memory impact. So the function we’re interested in is:

  1. renderBuilder :: Monad m => RenderSettings -> Conduit Event m Builder

In plain English, that means renderBuilder takes some settings (we’ll just use the defaults), and will then convert a stream of Events to a stream of Builders. This is looking pretty good, all we need now is a stream of Events.

Speaking of which, what should our XML document actually look like? It’s pretty simple, we have a sphinx:docset root element, a sphinx:schema element containing a single sphinx:field (which defines the content field), and then a sphinx:document for each document in our database. That last element will have an id attribute and a child content element. Below is an example of such a document:

  1. <sphinx:docset xmlns:sphinx="http://sphinxsearch.com/">
  2. <sphinx:schema>
  3. <sphinx:field name="content"/>
  4. </sphinx:schema>
  5. <sphinx:document id="1">
  6. <content>bar</content>
  7. </sphinx:document>
  8. <sphinx:document id="2">
  9. <content>foo bar baz</content>
  10. </sphinx:document>
  11. </sphinx:docset>

If you’re not familiar with XML namespaces, the xmlns: syntax and sphinx: prefixes may look pretty weird. I don’t want to get into an XML tutorial in this chapter, so I’ll avoid an explanation. If you’re curious, feel free to look up the XML namespace specification.

Every document is going to start off with the same events (start the docset, start the schema, etc) and end with the same event (end the docset). We’ll start off by defining those:

  1. toName :: Text -> X.Name
  2. toName x = X.Name x (Just "http://sphinxsearch.com/") (Just "sphinx")
  3. docset, schema, field, document, content :: X.Name
  4. docset = toName "docset"
  5. schema = toName "schema"
  6. field = toName "field"
  7. document = toName "document"
  8. content = "content" -- no prefix
  9. startEvents, endEvents :: [X.Event]
  10. startEvents =
  11. [ X.EventBeginDocument
  12. , X.EventBeginElement docset []
  13. , X.EventBeginElement schema []
  14. , X.EventBeginElement field [("name", [X.ContentText "content"])]
  15. , X.EventEndElement field
  16. , X.EventEndElement schema
  17. ]
  18. endEvents =
  19. [ X.EventEndElement docset
  20. ]

Now that we have the shell of our document, we need to get the Events for each individual document. This is actually a fairly simple function:

  1. entityToEvents :: Entity Doc -> [X.Event]
  2. entityToEvents (Entity docid doc) =
  3. [ X.EventBeginElement document [("id", [X.ContentText $ toPathPiece docid])]
  4. , X.EventBeginElement content []
  5. , X.EventContent $ X.ContentText $ unTextarea $ docContent doc
  6. , X.EventEndElement content
  7. , X.EventEndElement document
  8. ]

We start the document element with an id attribute, start the content, insert the content, and then close both elements. We use toPathPiece to convert a DocId into a Text value. Next, we need to be able to convert a stream of these entities into a stream of events. For this, we can use the built-in concatMap function from Data.Conduit.List: CL.concatMap entityToEvents.

But what we really want is to stream those events directly from the database. For most of this book, we’ve used the selectList function, but Persistent also provides the (more powerful) selectSource function. So we end up with the function:

  1. docSource :: Source (YesodDB Searcher) X.Event
  2. docSource = selectSource [] [] $= CL.concatMap entityToEvents

The $= operator joins together a source and a conduit into a new source. Now that we have our Event source, all we need to do is surround it with the document start and end events. With Source‘s Monad instance, this is a piece of cake:

  1. fullDocSource :: Source (YesodDB Searcher) X.Event
  2. fullDocSource = do
  3. mapM_ yield startEvents
  4. docSource
  5. mapM_ yield endEvents

Now we need to tie it together in getXmlpipeR. To do so, we’ll use the respondSourceDB function mentioned earlier. The last trick we need to do is convert our stream of Events into a stream of Chunk Builders. Converting to a stream of Builders is achieved with renderBuilder, and finally we’ll just wrap each Builder in its own Chunk:

  1. getXmlpipeR :: Handler TypedContent
  2. getXmlpipeR =
  3. respondSourceDB "text/xml"
  4. $ fullDocSource
  5. $= renderBuilder def
  6. $= CL.map Chunk

Full code

  1. {-# LANGUAGE FlexibleContexts #-}
  2. {-# LANGUAGE GADTs #-}
  3. {-# LANGUAGE GeneralizedNewtypeDeriving #-}
  4. {-# LANGUAGE MultiParamTypeClasses #-}
  5. {-# LANGUAGE OverloadedStrings #-}
  6. {-# LANGUAGE QuasiQuotes #-}
  7. {-# LANGUAGE TemplateHaskell #-}
  8. {-# LANGUAGE TypeFamilies #-}
  9. {-# LANGUAGE ViewPatterns #-}
  10. import Control.Applicative ((<$>), (<*>))
  11. import Control.Monad (forM)
  12. import Control.Monad.Logger (runStdoutLoggingT)
  13. import Data.Conduit
  14. import qualified Data.Conduit.List as CL
  15. import Data.Maybe (catMaybes)
  16. import Data.Monoid (mconcat)
  17. import Data.Text (Text)
  18. import qualified Data.Text as T
  19. import Data.Text.Lazy.Encoding (decodeUtf8)
  20. import qualified Data.XML.Types as X
  21. import Database.Persist.Sqlite
  22. import Text.Blaze.Html (preEscapedToHtml)
  23. import qualified Text.Search.Sphinx as S
  24. import qualified Text.Search.Sphinx.ExcerptConfiguration as E
  25. import qualified Text.Search.Sphinx.Types as ST
  26. import Text.XML.Stream.Render (def, renderBuilder)
  27. import Yesod
  28. share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
  29. Doc
  30. title Text
  31. content Textarea
  32. |]
  33. data Searcher = Searcher
  34. { connPool :: ConnectionPool
  35. }
  36. mkYesod "Searcher" [parseRoutes|
  37. / HomeR GET
  38. /doc/#DocId DocR GET
  39. /add-doc AddDocR POST
  40. /search SearchR GET
  41. /search/xmlpipe XmlpipeR GET
  42. |]
  43. instance Yesod Searcher
  44. instance YesodPersist Searcher where
  45. type YesodPersistBackend Searcher = SqlBackend
  46. runDB action = do
  47. Searcher pool <- getYesod
  48. runSqlPool action pool
  49. instance YesodPersistRunner Searcher where
  50. getDBRunner = defaultGetDBRunner connPool
  51. instance RenderMessage Searcher FormMessage where
  52. renderMessage _ _ = defaultFormMessage
  53. addDocForm :: Html -> MForm Handler (FormResult Doc, Widget)
  54. addDocForm = renderTable $ Doc
  55. <$> areq textField "Title" Nothing
  56. <*> areq textareaField "Contents" Nothing
  57. searchForm :: Html -> MForm Handler (FormResult Text, Widget)
  58. searchForm = renderDivs $ areq (searchField True) "Query" Nothing
  59. getHomeR :: Handler Html
  60. getHomeR = do
  61. docCount <- runDB $ count ([] :: [Filter Doc])
  62. ((_, docWidget), _) <- runFormPost addDocForm
  63. ((_, searchWidget), _) <- runFormGet searchForm
  64. let docs = if docCount == 1
  65. then "There is currently 1 document."
  66. else "There are currently " ++ show docCount ++ " documents."
  67. defaultLayout
  68. [whamlet|
  69. <p>Welcome to the search application. #{docs}
  70. <form method=post action=@{AddDocR}>
  71. <table>
  72. ^{docWidget}
  73. <tr>
  74. <td colspan=3>
  75. <input type=submit value="Add document">
  76. <form method=get action=@{SearchR}>
  77. ^{searchWidget}
  78. <input type=submit value=Search>
  79. |]
  80. postAddDocR :: Handler Html
  81. postAddDocR = do
  82. ((res, docWidget), _) <- runFormPost addDocForm
  83. case res of
  84. FormSuccess doc -> do
  85. docid <- runDB $ insert doc
  86. setMessage "Document added"
  87. redirect $ DocR docid
  88. _ -> defaultLayout
  89. [whamlet|
  90. <form method=post action=@{AddDocR}>
  91. <table>
  92. ^{docWidget}
  93. <tr>
  94. <td colspan=3>
  95. <input type=submit value="Add document">
  96. |]
  97. getDocR :: DocId -> Handler Html
  98. getDocR docid = do
  99. doc <- runDB $ get404 docid
  100. defaultLayout
  101. [whamlet|
  102. <h1>#{docTitle doc}
  103. <div .content>#{docContent doc}
  104. |]
  105. data Result = Result
  106. { resultId :: DocId
  107. , resultTitle :: Text
  108. , resultExcerpt :: Html
  109. }
  110. getResult :: DocId -> Doc -> Text -> IO Result
  111. getResult docid doc qstring = do
  112. excerpt' <- S.buildExcerpts
  113. excerptConfig
  114. [escape $ docContent doc]
  115. "searcher"
  116. qstring
  117. let excerpt =
  118. case excerpt' of
  119. ST.Ok texts -> preEscapedToHtml $ mconcat texts
  120. _ -> ""
  121. return Result
  122. { resultId = docid
  123. , resultTitle = docTitle doc
  124. , resultExcerpt = excerpt
  125. }
  126. where
  127. excerptConfig = E.altConfig { E.port = 9312 }
  128. escape :: Textarea -> Text
  129. escape =
  130. T.concatMap escapeChar . unTextarea
  131. where
  132. escapeChar '<' = "&lt;"
  133. escapeChar '>' = "&gt;"
  134. escapeChar '&' = "&amp;"
  135. escapeChar c = T.singleton c
  136. getResults :: Text -> Handler [Result]
  137. getResults qstring = do
  138. sphinxRes' <- liftIO $ S.query config "searcher" qstring
  139. case sphinxRes' of
  140. ST.Ok sphinxRes -> do
  141. let docids = map (toSqlKey . ST.documentId) $ ST.matches sphinxRes
  142. fmap catMaybes $ runDB $ forM docids $ \docid -> do
  143. mdoc <- get docid
  144. case mdoc of
  145. Nothing -> return Nothing
  146. Just doc -> liftIO $ Just <$> getResult docid doc qstring
  147. _ -> error $ show sphinxRes'
  148. where
  149. config = S.defaultConfig
  150. { S.port = 9312
  151. , S.mode = ST.Any
  152. }
  153. getSearchR :: Handler Html
  154. getSearchR = do
  155. ((formRes, searchWidget), _) <- runFormGet searchForm
  156. searchResults <-
  157. case formRes of
  158. FormSuccess qstring -> getResults qstring
  159. _ -> return []
  160. defaultLayout $ do
  161. toWidget
  162. [lucius|
  163. .excerpt {
  164. color: green; font-style: italic
  165. }
  166. .match {
  167. background-color: yellow;
  168. }
  169. |]
  170. [whamlet|
  171. <form method=get action=@{SearchR}>
  172. ^{searchWidget}
  173. <input type=submit value=Search>
  174. $if not $ null searchResults
  175. <h1>Results
  176. $forall result <- searchResults
  177. <div .result>
  178. <a href=@{DocR $ resultId result}>#{resultTitle result}
  179. <div .excerpt>#{resultExcerpt result}
  180. |]
  181. getXmlpipeR :: Handler TypedContent
  182. getXmlpipeR =
  183. respondSourceDB "text/xml"
  184. $ fullDocSource
  185. $= renderBuilder def
  186. $= CL.map Chunk
  187. entityToEvents :: (Entity Doc) -> [X.Event]
  188. entityToEvents (Entity docid doc) =
  189. [ X.EventBeginElement document [("id", [X.ContentText $ toPathPiece docid])]
  190. , X.EventBeginElement content []
  191. , X.EventContent $ X.ContentText $ unTextarea $ docContent doc
  192. , X.EventEndElement content
  193. , X.EventEndElement document
  194. ]
  195. fullDocSource :: Source (YesodDB Searcher) X.Event
  196. fullDocSource = do
  197. mapM_ yield startEvents
  198. docSource
  199. mapM_ yield endEvents
  200. docSource :: Source (YesodDB Searcher) X.Event
  201. docSource = selectSource [] [] $= CL.concatMap entityToEvents
  202. toName :: Text -> X.Name
  203. toName x = X.Name x (Just "http://sphinxsearch.com/") (Just "sphinx")
  204. docset, schema, field, document, content :: X.Name
  205. docset = toName "docset"
  206. schema = toName "schema"
  207. field = toName "field"
  208. document = toName "document"
  209. content = "content" -- no prefix
  210. startEvents, endEvents :: [X.Event]
  211. startEvents =
  212. [ X.EventBeginDocument
  213. , X.EventBeginElement docset []
  214. , X.EventBeginElement schema []
  215. , X.EventBeginElement field [("name", [X.ContentText "content"])]
  216. , X.EventEndElement field
  217. , X.EventEndElement schema
  218. ]
  219. endEvents =
  220. [ X.EventEndElement docset
  221. ]
  222. main :: IO ()
  223. main = runStdoutLoggingT $ withSqlitePool "searcher.db3" 10 $ \pool -> liftIO $ do
  224. runSqlPool (runMigration migrateAll) pool
  225. warp 3000 $ Searcher pool