Search.purs 8.37 KB
Newer Older
1 2
module Gargantext.Components.Search where

3
import Gargantext.Prelude (class Eq, class Show)
4 5
import Data.Argonaut as Argonaut
import Data.Generic.Rep (class Generic)
6 7
import Data.Eq.Generic (genericEq)
import Data.Show.Generic (genericShow)
8
import Data.Maybe (Maybe)
9

10
import Gargantext.Utils.Argonaut (genericSumDecodeJson, genericSumEncodeJson, genericEnumDecodeJson, genericEnumEncodeJson)
11 12 13 14 15 16 17 18

-- Example:
--   [["machine","learning"],["artificial","intelligence"]]
-- This searches for documents with "machine learning" or "artificial intelligence"
type TextQuery = Array (Array String)
------------------------------------------------------------------------
data SearchType = SearchDoc | SearchContact

19 20 21
derive instance Eq SearchType
derive instance Generic SearchType _
instance Show SearchType where
22
  show = genericShow
23
instance Argonaut.DecodeJson SearchType where
24
  decodeJson = genericEnumDecodeJson
25
instance Argonaut.EncodeJson SearchType where
26
  encodeJson = genericEnumEncodeJson
27 28
------------------------------------------------------------------------

29
data SearchQuery = SearchQuery { query :: Array String, expected :: SearchType }
30

31 32 33
derive instance Eq SearchQuery
derive instance Generic SearchQuery _
instance Show SearchQuery where
34
  show = genericShow
35
instance Argonaut.DecodeJson SearchQuery where
36
  decodeJson = genericSumDecodeJson
37
instance Argonaut.EncodeJson SearchQuery where
38 39 40
  encodeJson = genericSumEncodeJson

------------------------------------------------------------------------
41
------------------------------------------------------------------------
42
data SearchResult = SearchResult { result :: SearchResultTypes }
43

44 45 46
derive instance Eq SearchResult
derive instance Generic SearchResult _
instance Show SearchResult where
47
  show = genericShow
48
instance Argonaut.DecodeJson SearchResult where
49
  decodeJson = genericSumDecodeJson
50
instance Argonaut.EncodeJson SearchResult where
51 52
  encodeJson = genericSumEncodeJson

53

54
------------------------------------------------------------------------
55 56
data SearchResultTypes = SearchResultDoc     { docs     :: Array Document}
                       | SearchNoResult      { message  :: String        }
57
                       | SearchResultContact { contacts :: Array Contact }
58

59 60 61
derive instance Eq SearchResultTypes
derive instance Generic SearchResultTypes _
instance Show SearchResultTypes where
62
  show = genericShow
63
instance Argonaut.DecodeJson SearchResultTypes where
64
  decodeJson = genericSumDecodeJson
65
instance Argonaut.EncodeJson SearchResultTypes where
66 67 68
  encodeJson = genericSumEncodeJson


69
------------------------------------------------------------------------
70
data Document =
71 72 73
  Document { id         :: Int
           , created    :: String
           , title      :: String
74
           , hyperdata  :: HyperdataRowDocument
75 76
           , category   :: Int
           , score      :: Int
77
           }
78 79
derive instance Generic Document _
instance Eq Document where
80
  eq = genericEq
81
instance Show Document where
82
  show = genericShow
83
instance Argonaut.DecodeJson Document where
84
  decodeJson = genericSumDecodeJson
85
instance Argonaut.EncodeJson Document where
86 87 88
  encodeJson = genericSumEncodeJson

------------------------------------------------------------------------
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
newtype HyperdataRowDocument =
  HyperdataRowDocument { bdd                :: Maybe String
                       , doi                :: Maybe String
                       , url                :: Maybe String
                       , uniqId             :: Maybe String
                       , uniqIdBdd          :: Maybe String
                       , page               :: Maybe Int
                       , title              :: Maybe String
                       , authors            :: Maybe String
                       , institutes         :: Maybe String
                       , source             :: Maybe String
                       , abstract           :: Maybe String
                       , publication_date   :: Maybe String
                       , publication_year   :: Maybe Int
                       , publication_month  :: Maybe Int
                       , publication_day    :: Maybe Int
                       , publication_hour   :: Maybe Int
                       , publication_minute :: Maybe Int
                       , publication_second :: Maybe Int
                       , language_iso2      :: Maybe String
                       }

111 112 113
derive instance Eq HyperdataRowDocument
derive instance Generic HyperdataRowDocument _
instance Show HyperdataRowDocument where
114
  show = genericShow
115
instance Argonaut.DecodeJson HyperdataRowDocument where
116
  decodeJson = genericSumDecodeJson
117
instance Argonaut.EncodeJson HyperdataRowDocument where
118 119 120 121 122 123
  encodeJson = genericSumEncodeJson

------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
data Contact =
124 125 126 127
  Contact  { c_id         :: Int
           , c_created    :: String
           , c_hyperdata  :: HyperdataRowContact
           , c_score      :: Int
128
           , c_annuaireId :: Int
129 130
           }

131 132 133
derive instance Eq Contact
derive instance Generic Contact _
instance Show Contact where
134
  show = genericShow
135
instance Argonaut.DecodeJson Contact where
136
  decodeJson = genericSumDecodeJson
137
instance Argonaut.EncodeJson Contact where
138 139 140
  encodeJson = genericSumEncodeJson


141 142 143 144 145
data HyperdataRowContact =
     HyperdataRowContact { firstname    :: String
                         , lastname   :: String
                         , labs       :: String
                         }
146 147 148
derive instance Eq HyperdataRowContact
derive instance Generic HyperdataRowContact _
instance Show HyperdataRowContact where
149
  show = genericShow
150
instance Argonaut.DecodeJson HyperdataRowContact where
151
  decodeJson = genericSumDecodeJson
152
instance Argonaut.EncodeJson HyperdataRowContact where
153 154 155 156 157
  encodeJson = genericSumEncodeJson




158 159 160 161 162 163 164 165 166 167
data HyperdataContact =
     HyperdataContact { bdd    :: Maybe String
                      , who    :: Maybe ContactWho
                      , "where" :: Array ContactWhere
                      , title   :: Maybe String
                      , source         :: Maybe String
                      , lastValidation :: Maybe String
                      , uniqIdBdd      :: Maybe String
                      , uniqId         :: Maybe String
                      }
168 169 170
derive instance Eq HyperdataContact
derive instance Generic HyperdataContact _
instance Show HyperdataContact where
171
  show = genericShow
172
instance Argonaut.DecodeJson HyperdataContact where
173
  decodeJson = genericSumDecodeJson
174
instance Argonaut.EncodeJson HyperdataContact where
175 176 177 178 179 180 181 182 183 184
  encodeJson = genericSumEncodeJson

-------
data ContactWho =
     ContactWho { id          :: Maybe String
                , firstName   :: Maybe String
                , lastName    :: Maybe String
                , keywords :: Array String
                , freetags :: Array String
                }
185 186 187
derive instance Eq ContactWho
derive instance Generic ContactWho _
instance Show ContactWho where
188
  show = genericShow
189
instance Argonaut.DecodeJson ContactWho where
190
  decodeJson = genericSumDecodeJson
191
instance Argonaut.EncodeJson ContactWho where
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
  encodeJson = genericSumEncodeJson


data ContactWhere =
     ContactWhere { organization :: Array String
                  , labTeamDepts :: Array String

                  , role         :: Maybe String

                  , office       :: Maybe String
                  , country      :: Maybe String
                  , city         :: Maybe String

                  , touch        :: Maybe ContactTouch

                  , entry        :: Maybe String
                  , exit         :: Maybe String
                  }
210 211 212
derive instance Eq ContactWhere
derive instance Generic ContactWhere _
instance Show ContactWhere where
213
  show = genericShow
214
instance Argonaut.DecodeJson ContactWhere where
215
  decodeJson = genericSumDecodeJson
216
instance Argonaut.EncodeJson ContactWhere where
217 218 219 220 221 222 223 224
  encodeJson = genericSumEncodeJson


data ContactTouch =
     ContactTouch { mail      :: Maybe String
                  , phone     :: Maybe String
                  , url       :: Maybe String
                  }
225 226 227
derive instance Eq ContactTouch
derive instance Generic ContactTouch _
instance Show ContactTouch where
228
  show = genericShow
229
instance Argonaut.DecodeJson ContactTouch where
230
  decodeJson = genericSumDecodeJson
231
instance Argonaut.EncodeJson ContactTouch where
232 233
  encodeJson = genericSumEncodeJson