module Text.Search.Sphinx.Types (
module Text.Search.Sphinx.Types
, ByteString ) where
import Data.ByteString.Lazy (ByteString)
import Data.Int (Int64)
import Data.Maybe (Maybe, isJust)
import Data.Text (Text,empty)
data Query = Query { queryString :: Text
, queryIndexes :: Text
, queryComment :: Text
} deriving (Show)
data SearchdCommand = ScSearch
| ScExcerpt
| ScUpdate
| ScKeywords
deriving (Show, Enum)
searchdCommand :: SearchdCommand -> Int
searchdCommand = fromEnum
data VerCommand = VcSearch
| VcExcerpt
| VcUpdate
| VcKeywords
deriving (Show)
#ifdef ONE_ONE_BETA
verCommand VcSearch = 0x117
verCommand VcExcerpt = 0x102
#else
verCommand VcSearch = 0x118
verCommand VcExcerpt = 0x103
#endif
verCommand VcUpdate = 0x101
verCommand VcKeywords = 0x100
data Status = OK
| RETRY
| WARNING
| ERROR Int
deriving (Show)
data QueryStatus = QueryOK
| QueryWARNING
| QueryERROR Int
deriving (Show)
toQueryStatus 0 = QueryOK
toQueryStatus 3 = QueryWARNING
toQueryStatus 2 = error "Didn't think retry was possible"
toQueryStatus n = QueryERROR n
toStatus 0 = OK
toStatus 2 = RETRY
toStatus 3 = WARNING
toStatus n = ERROR n
data MatchMode = All
| Any
| Phrase
| Boolean
| Extended
| Fullscan
| Extended2
deriving (Show, Enum)
data Rank = ProximityBm25
| Bm25
| None
| WordCount
| Proximity
| MatchAny
| Fieldmask
| Sph04
| Total
deriving (Show, Enum)
data Sort = Relevance
| AttrDesc
| AttrAsc
| TimeSegments
| SortExtended
| Expr
deriving (Show, Enum)
data Filter = ExclusionFilter Filter
| FilterValues String [Int64]
| FilterRange String Int64 Int64
deriving (Show)
exclude filter = ExclusionFilter filter
fromEnumFilter (FilterValues _ _) = 0
fromEnumFilter (FilterRange _ _ _) = 1
data AttrT = AttrTUInt
| AttrTTimestamp
| AttrTStr2Ordinal
| AttrTBool
| AttrTFloat
| AttrTBigInt
| AttrTString
| AttrTWordCount
| AttrTMulti AttrT
deriving (Show)
instance Enum AttrT where
toEnum = toAttrT
fromEnum = attrT
toAttrT 1 = AttrTUInt
toAttrT 2 = AttrTTimestamp
toAttrT 3 = AttrTStr2Ordinal
toAttrT 4 = AttrTBool
toAttrT 5 = AttrTFloat
toAttrT 6 = AttrTBigInt
toAttrT 7 = AttrTString
toAttrT 8 = AttrTWordCount
toAttrT 0x40000001 = AttrTMulti AttrTUInt
attrMultiMask = 0x40000000
attrT AttrTUInt = 1
attrT AttrTTimestamp = 2
attrT AttrTStr2Ordinal = 3
attrT AttrTBool = 4
attrT AttrTFloat = 5
attrT AttrTBigInt = 6
attrT AttrTString = 7
attrT AttrTWordCount = 8
attrT (AttrTMulti AttrTUInt) = 0x40000001
data GroupByFunction = Day
| Week
| Month
| Year
| Attr
| AttrPair
deriving (Show, Enum)
data QueryResult = QueryResult {
matches :: [Match]
, total :: Int
, totalFound :: Int
, words :: [(Text, Int, Int)]
, attributeNames :: [ByteString]
}
deriving Show
data SingleResult = QueryOk QueryResult
| QueryWarning Text QueryResult
| QueryError Int Text
deriving (Show)
data Result a = Ok a
| Warning Text a
| Error Int Text
| Retry Text
deriving (Show)
data Match = Match {
documentId :: Int64
, documentWeight :: Int
, attributeValues :: [Attr]
}
deriving Show
instance Eq Match where
d1 == d2 = documentId d1 == documentId d2
data Attr = AttrMulti [Attr]
| AttrUInt Int
| AttrBigInt Int64
| AttrString Text
| AttrFloat Float
deriving (Show)