TCache-0.9.0.2: A Transactional cache with user-defined persistence

Safe HaskellSafe-Infered

Data.TCache.IndexText

Description

Implements full text indexation (indexText) and text search(contains), as an addition to the query language implemented in IndexQuery it also can index the lists of elements in a field (with indexList) so that it is possible to ask for the registers that contains a given element in the given field (with containsElem)

An example of full text search:

data Doc= Doc{title, body :: String} deriving (Read,Show, Typeable)
instance Indexable Doc where
  key Doc{title=t}= t

instance Serializable Doc  where
  serialize= pack . show
  deserialize= read . unpack

main= do
  indexText  body T.pack
  let doc= Doc{title=  title, body=  hola que tal estamos}
  rdoc <- atomically $ newDBRef doc
  r1 <- atomically $ select title $ body contains hola que tal
  print r1

atomically $ writeDBRef rdoc  doc{ body=  que tal}
  r <- atomically $ select title $ body contains hola que tal
  print r
  if  r1 == [title doc] then print OK else print FAIL
  if  r== [] then print OK else print FAIL

Synopsis

Documentation

indexTextSource

Arguments

:: (IResource a, Typeable a, Typeable b) 
=> (a -> b)

field to index

-> (b -> Text)

method to convert the field content to Text (for example pack in case of String fields). This permits to index non Textual fields

-> IO () 

start a trigger to index the contents of a register field

indexListSource

Arguments

:: (IResource a, Typeable a, Typeable b) 
=> (a -> b)

field to index

-> (b -> [Text])

method to convert the field content to Text (for example pack in case of String fields). This permits to index non Textual fields

-> IO () 

containsSource

Arguments

:: (IResource a, Typeable a, Typeable b) 
=> (a -> b)

field to search in

-> String

text to search

-> STM [DBRef a] 

return the DBRefs whose fields include all the words of length three or more in the requested text contents

containsElem :: (IResource a, Typeable a, Typeable b) => (a -> b) -> String -> STM [DBRef a]Source