Sphinx is a search server, and powers the search feature on many sites, including Yesod’s own site. 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 straightforward Persistent code, and we won’t dwell on it much in this chapter.
Accessing Sphinx search results from inside Yesod. Thanks to the
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.
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
search is a debugging utility that will run simple queries against ...