Skip to content

Commit

Permalink
issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
agocorona committed Jul 5, 2013
1 parent 14d6009 commit b59dec0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 11 additions & 4 deletions Data/TCache/IndexQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ selectorIndex selector rindex pobject mobj = do
index
:: (Queriable reg a) =>
(reg -> a) -> IO ()
index sel=
index sel= do
let [one, two]= typeRepArgs $! typeOf sel
rindex= getDBRef $! keyIndex one two
in addTrigger $ selectorIndex sel rindex

addTrigger $ selectorIndex sel rindex
withResources [] $ const [ (Index M.empty `asTypeOf` indexsel sel )]
where
indexsel :: (reg-> a) -> Index reg a
indexsel= undefined
-- | implement the relational-like operators, operating on record fields
class RelationOps field1 field2 res | field1 field2 -> res where
(.==.) :: field1 -> field2 -> STM res
Expand Down Expand Up @@ -289,7 +292,11 @@ indexOf selector= do
let [one, two]= typeRepArgs $! typeOf selector
let rindex= getDBRef $! keyIndex one two
mindex <- readDBRef rindex
case mindex of Just (Index index) -> return $ M.toList index; _ -> return []
case mindex of
Just (Index index) -> return $ M.toList index;
_ -> do
let fields= show $ typeOf selector
error $ "the index for "++ fields ++" do not exist. At main, use \"Data.TCache.IdexQuery.index\" to start indexing this field"

retrieve :: Queriable reg a => (reg -> a) -> a -> (a -> a -> Bool) -> STM[DBRef reg]
retrieve field value op= do
Expand Down
17 changes: 14 additions & 3 deletions Data/TCache/IndexText.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,24 @@ indexText
=> (a -> b) -- ^ field to index
-> (b -> T.Text) -- ^ method to convert the field content to lazy Text (for example `pack` in case of String fields). This permits to index non Textual fields
-> IO ()
indexText sel convert= addTrigger (indext sel (words1 . convert))
indexText sel convert= do
addTrigger (indext sel (words1 . convert))
let [t1,t2]= typeRepArgs $! typeOf sel
t= show t1 ++ show t2
withResources [] $ const [IndexText t 0 M.empty M.empty M.empty]

-- | trigger the indexation of list fields with elements convertible to Text
indexList
:: (IResource a, Typeable a, Typeable b)
=> (a -> b) -- ^ field to index
-> (b -> [T.Text]) -- ^ method to convert a field element to Text (for example `pack . show` in case of elemets with Show instances)
-> IO ()
indexList sel convert= addTrigger (indext sel convert)
indexList sel convert= do
addTrigger (indext sel convert)
let [t1,t2]= typeRepArgs $! typeOf sel
t= show t1 ++ show t2
withResources [] $ const [IndexText t 0 M.empty M.empty M.empty]



indext :: (IResource a, Typeable a,Typeable b)
Expand Down Expand Up @@ -191,7 +200,9 @@ containsElem sel wstr = do
mr <- withSTMResources [IndexText t u u u u]
$ \[r] -> resources{toReturn= r}
case mr of
Nothing -> return []
Nothing -> do
let fields= show $ typeOf sel
error $ "the index for "++ fields ++" do not exist. At main, use \"Data.TCache.IdexQuery.index\" to start indexing this field"
Just (IndexText t n _ mmapIntString map1) ->
case M.lookup w map1 of
Nothing -> return []
Expand Down

0 comments on commit b59dec0

Please sign in to comment.