MyNixOS website logo
Description

Haskell bindings to the Sphinx full-text searching daemon.

Haskell bindings to the Sphinx full-text searching daemon. Compatible with Sphinx version 2.0

A haskell implementation of a sphinx full text search client. Sphinx is a very fast and featureful full-text search daemon. Version 0.4 is Compatible with sphinx version 1.1-beta Version 0.5+ is Compatible with sphinx version 2.0, but you can instead pass the version-one-one build flag. On hackage.

Usage

Constructing Queries

The data type Query is used to represent queries to the server. It specifies a search string and the indexes to run the query on, as well as a comment, which may be the empty string. In order to run a query on all indexes, use "*" in the index field.

The convenience function query executes a single query and constructs the Query by itself, so you don't have to.

To execute more than one Query, use runQueries. Details are below in the section Batch Queries. To construct simple queries, you can also use simpleQuery :: Text -> Query which constructs a Query over all indexes. Don't forget that you can use record updates on a Query.

In extended mode you may want to escape special query characters with escapeString.

All interaction with the server, including sending queries and receiving results, is based on the Data.Text string type. You might therefore want to enable the OverloadedStrings pragma.

Excerpts and XML Indexes

buildExcerpts creates highlighted excerpts.

You will probably need to import the types as well:

import qualified Text.Search.Sphinx as Sphinx
import qualified Text.Search.Sphinx.Types as SphinxT

There is also an Indexable module for generating an xml file of data to be indexed.

Batch Queries

You can send more than one query per request to the server (which may enable server-side query optimization in certain cases. Refer to the Sphinx manual for details.) The function runQueries pipelines multiple queries together. If you are trying to combine the results, there are some helpers such as maybeQueries and resultsToMatches.

      mr <- Sphinx.maybeQueries sphinxLogger sphinxConfig [
                 SphinxT.Query query1 "db1" ""
               , SphinxT.Query query1 "db2" ""
               , SphinxT.Query query2 "db1" ""
               , SphinxT.Query query2 "db2" ""
               ]
      case mr of
        Nothing -> return Nothing
        Just rs -> do
          let combined = Sphinx.resultsToMatches 20 rs
          if null combined
             then return Nothing
             else return $ Just combined

A note for those transitioning from 0.5.* to 0.6: the function addQueries has been removed. You can now directly send a list of Query to the server by using runQueries, which will handle the serialization for you behind the scenes.

Encoding

The sphinx server itself does not know about encodings except for the difference between single-byte encodings and multi-byte encodings. It assumes that all incoming queries are already properly encoded and matches the raw bytes it receives; the same holds for the results returned by the server. Hence the responsibilty for using the proper encoding (and decoding) routines lies with the caller.

Version 0.6.0 of haskell-sphinx-client introduces the encoding field in both the Configuration data type and the ExcerptConfiguration data type. The library handles proper encoding and decoding in the background; just make sure you set the right encoding setting in the configuration!

Details

Implemenation

Implementation of API as detailed in the documentation. Most search and buildExcerpts features are implemented.

History

Originally written by Tupil and maintained by Chris Eidhof for an earlier version of sphinx. Greg Weber improved the library and updated it for the latest version of sphinx. Aleksandar Dimitrov updated the library to use Text. The Haskell team of Chordify is now maintaining the library.

Usage of this haskell client

Tupil originally wrote this for use on a commercial project. This sphinx package is now finding some use in the Yesod community. Here is a well described example usage, but do keep in mind there is no requirement to tie the generation of sphinx documents to your web application, just your database. Used in Yesod applications yesdoweb.com and eatnutrients.com.

Metadata

Version

0.6.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows