License | MIT |
---|---|
Maintainer | Uwe Schmidt |
Stability | experimental |
Portability | none portable |
Safe Haskell | None |
Language | Haskell98 |
Common data types and and smart constructors for calling a hunt server from a client.
Values of the Command datatype and its component types, e.g Query, ApiDocument, and others can be constructed with the "smart" construtors defined in this module
The module is intended to be imported qualified,
eg like import qualified Hunt.ClientInterface as HI
.
- data Command
- data ApiDocument = ApiDocument {}
- class Huntable x where
- huntURI :: x -> URI
- huntIndexMap :: x -> IndexMap
- huntDescr :: x -> Description
- toApiDocument :: x -> ApiDocument
- type Content = Text
- type Context = Text
- data ContextSchema
- type Description = DocDesc
- type IndexMap = Map Context Content
- type RegEx = Text
- data StatusCmd
- type URI = Text
- type Weight = Score
- data CmdError = ResError {}
- newtype CmdRes a = CmdRes {
- unCmdRes :: a
- data CmdResult
- = ResOK
- | ResSearch { }
- | ResCompletion { }
- | ResSuggestion { }
- | ResGeneric { }
- data LimitedResult x = LimitedResult {}
- data Score
- cmdSearch :: Query -> Command
- cmdCompletion :: Query -> Command
- cmdSelect :: Query -> Command
- cmdInsertDoc :: ApiDocument -> Command
- cmdUpdateDoc :: ApiDocument -> Command
- cmdDeleteDoc :: URI -> Command
- cmdDeleteDocsByQuery :: Query -> Command
- cmdLoadIndex :: FilePath -> Command
- cmdStoreIndex :: FilePath -> Command
- cmdInsertContext :: Context -> ContextSchema -> Command
- cmdDeleteContext :: Context -> Command
- cmdStatus :: StatusCmd -> Command
- cmdSequence :: [Command] -> Command
- cmdNOOP :: Command
- setSelectedFields :: [Text] -> Command -> Command
- setMaxResults :: Int -> Command -> Command
- setResultOffset :: Int -> Command -> Command
- setWeightIncluded :: Command -> Command
- createContextCommands :: [ApiDocument] -> Command
- mkApiDoc :: URI -> ApiDocument
- setDescription :: Description -> ApiDocument -> ApiDocument
- getDescription :: ApiDocument -> Description
- addDescription :: ToJSON v => Text -> v -> ApiDocument -> ApiDocument
- remDescription :: Text -> ApiDocument -> ApiDocument
- changeDescription :: (Description -> Description) -> ApiDocument -> ApiDocument
- lookupDescription :: FromJSON v => Text -> ApiDocument -> Maybe v
- lookupDescriptionText :: Text -> ApiDocument -> Text
- setIndex :: IndexMap -> ApiDocument -> ApiDocument
- addToIndex :: Context -> Content -> ApiDocument -> ApiDocument
- getFromIndex :: Context -> ApiDocument -> Text
- changeIndex :: (IndexMap -> IndexMap) -> ApiDocument -> ApiDocument
- setDocWeight :: Score -> ApiDocument -> ApiDocument
- listToApiDoc :: Text -> [(Text, Text)] -> [(Text, Text)] -> ApiDocument
- insertCmdsToDocuments :: Command -> [ApiDocument]
- mkDescription :: [(Text, Text)] -> Description
- mapToDescr :: Map Text Text -> DocDesc
- insDescription :: ToJSON v => Text -> v -> Description -> Description
- emptyDescription :: Description
- fromDescription :: Description -> [(Text, Value)]
- data Query
- parseQuery :: String -> Either Text Query
- module Hunt.Query.Language.Builder
- printQuery :: Query -> Text
- completeQueries :: Query -> [Text] -> [Query]
- mkSchema :: ContextSchema
- setCxNoDefault :: ContextSchema -> ContextSchema
- setCxWeight :: Float -> ContextSchema -> ContextSchema
- setCxRegEx :: RegEx -> ContextSchema -> ContextSchema
- setCxUpperCase :: ContextSchema -> ContextSchema
- setCxLowerCase :: ContextSchema -> ContextSchema
- setCxZeroFill :: ContextSchema -> ContextSchema
- setCxText :: ContextSchema -> ContextSchema
- setCxInt :: ContextSchema -> ContextSchema
- setCxDate :: ContextSchema -> ContextSchema
- setCxPosition :: ContextSchema -> ContextSchema
- noScore :: Score
- defScore :: Score
- mkScore :: Float -> Score
- getScore :: Score -> Maybe Float
- sendCmdToFile :: String -> Command -> IO ()
types used in commands
The "high-level" commands accepted by the Interpreter
/ JSON API.
These are translated to BasicCommand
s.
huntIndexMap :: x -> IndexMap Source
huntDescr :: x -> Description Source
toApiDocument :: x -> ApiDocument Source
data ContextSchema Source
The context schema information. Every context schema has a type and additional to adjust the behavior.
The regular expression splits the text into words which are then transformed by the given normalizations functions (e.g. to lower case).
type Description = DocDesc Source
The description of a document is a generic key value map.
types used in results
An error during processing of the command. This includes a error code and a message.
auxiliary type for parsing JSON CmdResult's of various kinds
usefull in hunt applications, not used within the hunt server
The result of an interpreted command.
ResOK | The command was processed successfully. |
ResSearch | The search results. |
ResCompletion | The auto-completion results. |
ResSuggestion | The simplified completion result |
ResGeneric | A generic JSON result. |
data LimitedResult x Source
Paginated result with an offset and chunk size.
Eq x => Eq (LimitedResult x) | |
Show x => Show (LimitedResult x) | |
ToJSON x => ToJSON (LimitedResult x) | |
FromJSON x => FromJSON (LimitedResult x) | |
NFData x => NFData (LimitedResult x) |
The score of a hit (either a document hit or a word hit). type Score = Float
Weight or score of a documents,
0.0
indicates: not set, so there is no need to work with Maybe's
wrapped in newtype to not mix up with Score's and Weight's in documents
Eq Score | |
Fractional Score | |
Num Score | |
Ord Score | |
Show Score | |
ToJSON Score | |
FromJSON Score | |
Monoid Score | |
Binary Score | |
NFData Score | |
Aggregate ScoredOccs Score | aggregate scored occurences to a score by aggregating first the positions and snd the doc ids used in computing the score of word in completion search |
Aggregate ScoredDocs Score | aggregate scored docs to a single score by summing up the scores and throw away the DocIds |
command construction
cmdCompletion :: Query -> Command Source
Create simple completion command
cmdInsertDoc :: ApiDocument -> Command Source
insert document
cmdUpdateDoc :: ApiDocument -> Command Source
update document
cmdDeleteDoc :: URI -> Command Source
delete document identified by an URI
cmdDeleteDocsByQuery :: Query -> Command Source
delete all documents idenitfied by a query
cmdLoadIndex :: FilePath -> Command Source
cmdStoreIndex :: FilePath -> Command Source
cmdInsertContext :: Context -> ContextSchema -> Command Source
cmdDeleteContext :: Context -> Command Source
cmdSequence :: [Command] -> Command Source
configuration options for search and completion
setSelectedFields :: [Text] -> Command -> Command Source
configure search command: set the list of attributes of the document decription to be included in the result list
example: setSelectedFields ["title", "date"]
restricts the documents
attributes to these to fields
setMaxResults :: Int -> Command -> Command Source
configure search and completion command: set the max # of results
setResultOffset :: Int -> Command -> Command Source
configure search command: set the starting offset of the result list
setWeightIncluded :: Command -> Command Source
configure search command: include document weight in result list
Misc
createContextCommands :: [ApiDocument] -> Command Source
create InsertContext Commands by a list of Insert Commands These contexts are not optimized and shoudn't be used in production code.
ApiDocument construction, configuration and access
mkApiDoc :: URI -> ApiDocument Source
build an api document with an uri as key and a description map as contents
setDescription :: Description -> ApiDocument -> ApiDocument Source
add an index map containing the text parts to be indexed
addDescription :: ToJSON v => Text -> v -> ApiDocument -> ApiDocument Source
remDescription :: Text -> ApiDocument -> ApiDocument Source
changeDescription :: (Description -> Description) -> ApiDocument -> ApiDocument Source
lookupDescription :: FromJSON v => Text -> ApiDocument -> Maybe v Source
lookupDescriptionText :: Text -> ApiDocument -> Text Source
setIndex :: IndexMap -> ApiDocument -> ApiDocument Source
add an index map containing the text parts to be indexed
addToIndex :: Context -> Content -> ApiDocument -> ApiDocument Source
getFromIndex :: Context -> ApiDocument -> Text Source
changeIndex :: (IndexMap -> IndexMap) -> ApiDocument -> ApiDocument Source
setDocWeight :: Score -> ApiDocument -> ApiDocument Source
add a document weight
Misc
wrapper for building an ApiDocument by lists
description construction
mkDescription :: [(Text, Text)] -> Description Source
insDescription :: ToJSON v => Text -> v -> Description -> Description Source
fromDescription :: Description -> [(Text, Value)] Source
Queries
query parsing
parseQuery :: String -> Either Text Query Source
Parse a query using the default syntax provided by the Hunt framework.
query construction
module Hunt.Query.Language.Builder
pretty printing
printQuery :: Query -> Text Source
Renders a text representation of a Query.
query completion
completeQueries :: Query -> [Text] -> [Query] Source
schema definition
mkSchema :: ContextSchema Source
the default schema: context type is text, no normalizers, weigth is 1.0, context is always searched by queries without context spec
setCxNoDefault :: ContextSchema -> ContextSchema Source
prevent searching in context, when not explicitly set in query
setCxWeight :: Float -> ContextSchema -> ContextSchema Source
set the regex for splitting a text into words
setCxRegEx :: RegEx -> ContextSchema -> ContextSchema Source
set the regex for splitting a text into words
setCxUpperCase :: ContextSchema -> ContextSchema Source
add a text normalizer for transformation into uppercase
setCxLowerCase :: ContextSchema -> ContextSchema Source
add a text normalizer for transformation into lowercase
setCxZeroFill :: ContextSchema -> ContextSchema Source
add a text normalizer for transformation into lowercase
setCxText :: ContextSchema -> ContextSchema Source
set the type of a context to text
setCxInt :: ContextSchema -> ContextSchema Source
set the type of a context to Int
setCxDate :: ContextSchema -> ContextSchema Source
set the type of a context to Date
setCxPosition :: ContextSchema -> ContextSchema Source
set the type of a context to Int
Weights and Scores
sendCmdToFile :: String -> Command -> IO () Source
send command as JSON into a file
the JSON is pretty printed with aeson-pretty,
""
and "-"
are used for output to stdout