Commit eace00f9 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] Duplicates

parent ca1549e0
...@@ -41,6 +41,7 @@ type FlowCmdM env err m = ...@@ -41,6 +41,7 @@ type FlowCmdM env err m =
type FlowCorpus a = ( AddUniqId a type FlowCorpus a = ( AddUniqId a
, UniqId a , UniqId a
, UniqParameters a
, InsertDb a , InsertDb a
, ExtractNgramsT a , ExtractNgramsT a
, HasText a , HasText a
...@@ -50,5 +51,6 @@ type FlowCorpus a = ( AddUniqId a ...@@ -50,5 +51,6 @@ type FlowCorpus a = ( AddUniqId a
type FlowInsertDB a = ( AddUniqId a type FlowInsertDB a = ( AddUniqId a
, UniqId a , UniqId a
, UniqParameters a
, InsertDb a , InsertDb a
) )
...@@ -57,7 +57,7 @@ module Gargantext.Database.Query.Table.Node.Document.Insert ...@@ -57,7 +57,7 @@ module Gargantext.Database.Query.Table.Node.Document.Insert
import Control.Lens (set, view) import Control.Lens (set, view)
import Control.Lens.Cons import Control.Lens.Cons
import Control.Lens.Prism import Control.Lens.Prism
import Data.Aeson (toJSON, encode, ToJSON) import Data.Aeson (toJSON, ToJSON)
import Data.Char (isAlpha) import Data.Char (isAlpha)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Text (Text) import Data.Text (Text)
...@@ -111,7 +111,7 @@ instance InsertDb HyperdataDocument ...@@ -111,7 +111,7 @@ instance InsertDb HyperdataDocument
, toField p , toField p
, toField $ maybe "No Title" (DT.take 255) (_hd_title h) , toField $ maybe "No Title" (DT.take 255) (_hd_title h)
, toField $ _hd_publication_date h -- TODO USE UTCTime , toField $ _hd_publication_date h -- TODO USE UTCTime
, (toField . toJSON) h , (toField . toJSON) (addUniqId h)
] ]
instance InsertDb HyperdataContact instance InsertDb HyperdataContact
...@@ -122,7 +122,7 @@ instance InsertDb HyperdataContact ...@@ -122,7 +122,7 @@ instance InsertDb HyperdataContact
, toField p , toField p
, toField $ maybe "Contact" (DT.take 255) (Just "Name") -- (_hc_name h) , toField $ maybe "Contact" (DT.take 255) (Just "Name") -- (_hc_name h)
, toField $ jour 0 1 1 -- TODO put default date , toField $ jour 0 1 1 -- TODO put default date
, (toField . toJSON) h , (toField . toJSON) (addUniqId h)
] ]
instance ToJSON a => InsertDb (Node a) instance ToJSON a => InsertDb (Node a)
...@@ -197,6 +197,10 @@ class AddUniqId a ...@@ -197,6 +197,10 @@ class AddUniqId a
where where
addUniqId :: a -> a addUniqId :: a -> a
class UniqParameters a
where
uniqParameters :: ParentId -> a -> Text
instance AddUniqId HyperdataDocument instance AddUniqId HyperdataDocument
where where
addUniqId = addUniqIdsDoc addUniqId = addUniqIdsDoc
...@@ -212,42 +216,32 @@ instance AddUniqId HyperdataDocument ...@@ -212,42 +216,32 @@ instance AddUniqId HyperdataDocument
shaParametersDoc = [ \d -> filterText $ maybeText (_hd_title d) shaParametersDoc = [ \d -> filterText $ maybeText (_hd_title d)
, \d -> filterText $ maybeText (_hd_abstract d) , \d -> filterText $ maybeText (_hd_abstract d)
, \d -> filterText $ maybeText (_hd_source d) , \d -> filterText $ maybeText (_hd_source d)
, \d -> maybeText (_hd_publication_date d) -- , \d -> maybeText (_hd_publication_date d)
] ]
instance UniqParameters HyperdataDocument
where
uniqParameters _ h = filterText $ DT.concat $ map maybeText $ [_hd_title h, _hd_abstract h, _hd_source h]
instance UniqParameters HyperdataContact
where
uniqParameters _ _ = ""
instance UniqParameters (Node a)
where
uniqParameters _ _ = undefined
filterText :: Text -> Text filterText :: Text -> Text
filterText = DT.toLower . (DT.filter isAlpha) filterText = DT.toLower . (DT.filter isAlpha)
-- TODO put this elsewhere (fix bin/gargantext-init/Main.hs too)
secret :: Text
secret = "Database secret to change"
instance (UniqParameters a, ToJSON a, HasDBid NodeType) => AddUniqId (Node a)
instance (AddUniqId a, ToJSON a, HasDBid NodeType) => AddUniqId (Node a)
where
addUniqId (Node nid _ t u p n d h) = Node nid hashId t u p n d h
where where
hashId = Just $ "\\x" <> (hash $ DT.concat params) addUniqId (Node nid _ t u p n d h) = Node nid (Just newHash) t u p n d h
params = [ secret
, cs $ show $ toDBid NodeDocument
, n
, cs $ show p
, cs $ encode h
]
{-
addUniqId n@(Node nid _ t u p n d h) =
case n of
Node HyperdataDocument -> Node nid hashId t u p n d h
where where
hashId = "\\x" <> (hash $ DT.concat params) newHash = "\\x" <> (hash $ uniqParameters (fromMaybe 0 p) h)
params = [ secret
, cs $ show $ toDBid NodeDocument
, n
, cs $ show p
, cs $ encode h
]
_ -> undefined
-}
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- * Uniqueness of document definition -- * Uniqueness of document definition
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment