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

3 4
import Gargantext.Prelude

5
import Data.Eq.Generic (genericEq)
6
import Data.Generic.Rep (class Generic)
7
import Data.Maybe (Maybe)
8
import Data.Newtype (class Newtype)
9 10
import Data.Show.Generic (genericShow)
import Gargantext.Utils.SimpleJSON as GUSJ
11 12
import Simple.JSON as JSON
import Simple.JSON.Generics as JSONG
13 14 15 16 17 18 19 20

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

21
derive instance Generic SearchType _
22 23 24 25
instance Eq SearchType where eq = genericEq
instance Show SearchType where show = genericShow
instance JSON.ReadForeign SearchType where readImpl = JSONG.enumSumRep
instance JSON.WriteForeign SearchType where writeImpl = JSON.writeImpl <<< show
26 27
------------------------------------------------------------------------

arturo's avatar
arturo committed
28 29 30 31 32
newtype SearchQuery = SearchQuery
  { query     :: Array String
  , expected  :: SearchType
  }

33
derive instance Generic SearchQuery _
34 35 36 37 38
derive instance Newtype SearchQuery _
instance Eq SearchQuery where eq = genericEq
instance Show SearchQuery where show = genericShow
derive newtype instance JSON.ReadForeign SearchQuery
derive newtype instance JSON.WriteForeign SearchQuery
39 40

------------------------------------------------------------------------
41
------------------------------------------------------------------------
42
newtype SearchResult = SearchResult { result :: SearchResultTypes }
43
derive instance Generic SearchResult _
44 45 46 47 48
derive instance Newtype SearchResult _
instance Eq SearchResult where eq = genericEq
instance Show SearchResult where show = genericShow
derive newtype instance JSON.ReadForeign SearchResult
derive newtype instance JSON.WriteForeign SearchResult
49

50
------------------------------------------------------------------------
51 52 53
data SearchResultTypes = SearchResultDoc     { docs     :: Array Document }
                       | SearchNoResult      { message  :: String         }
                       | SearchResultContact { contacts :: Array Contact  }
54
derive instance Generic SearchResultTypes _
55 56
instance Eq SearchResultTypes where eq = genericEq
instance Show SearchResultTypes where show = genericShow
57
instance JSON.ReadForeign SearchResultTypes where readImpl = GUSJ.taggedSumRep
58 59 60 61
instance JSON.WriteForeign SearchResultTypes where
  writeImpl (SearchResultDoc s)     = JSON.writeImpl s
  writeImpl (SearchNoResult s)      = JSON.writeImpl s
  writeImpl (SearchResultContact s) = JSON.writeImpl s
62

63
------------------------------------------------------------------------
64
newtype Document =
65 66 67
  Document { id         :: Int
           , created    :: String
           , title      :: String
68
           , hyperdata  :: HyperdataRowDocument
69 70
           , category   :: Int
           , score      :: Int
71
           }
72
derive instance Generic Document _
73 74 75 76 77
derive instance Newtype Document _
instance Eq Document where eq = genericEq
instance Show Document where show = genericShow
derive newtype instance JSON.ReadForeign Document
derive newtype instance JSON.WriteForeign Document
78 79

------------------------------------------------------------------------
80
newtype HyperdataRowDocument =
81
  HyperdataRowDocument { abstract           :: Maybe String
82
                       , authors            :: Maybe String
83 84
                       , bdd                :: Maybe String
                       , doi                :: Maybe String
85
                       , institutes         :: Maybe String
86 87
                       , language_iso2      :: Maybe String
                       , page               :: Maybe Int
88 89 90 91
                       , publication_date   :: Maybe String
                       , publication_day    :: Maybe Int
                       , publication_hour   :: Maybe Int
                       , publication_minute :: Maybe Int
92
                       , publication_month  :: Maybe Int
93
                       , publication_second :: Maybe Int
94 95 96 97 98 99
                       , publication_year   :: Maybe Int
                       , source             :: Maybe String
                       , title              :: Maybe String
                       , url                :: Maybe String
                       , uniqId             :: Maybe String
                       , uniqIdBdd          :: Maybe String
100 101
                       }

102
derive instance Generic HyperdataRowDocument _
103 104 105 106
instance Eq HyperdataRowDocument where eq = genericEq
instance Show HyperdataRowDocument where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataRowDocument
derive newtype instance JSON.WriteForeign HyperdataRowDocument
107 108 109 110

------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
111
newtype Contact =
112 113 114 115
  Contact  { c_id         :: Int
           , c_created    :: String
           , c_hyperdata  :: HyperdataRowContact
           , c_score      :: Int
116
           , c_annuaireId :: Int
117 118
           }

119
derive instance Generic Contact _
120 121 122 123 124 125 126 127 128
instance Eq Contact where eq = genericEq
instance Show Contact where show = genericShow
derive newtype instance JSON.ReadForeign Contact
derive newtype instance JSON.WriteForeign Contact

newtype HyperdataRowContact =
  HyperdataRowContact { firstname :: String
                      , lastname  :: String
                      , labs      :: String
129
                      }
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
derive instance Generic HyperdataRowContact _
instance Eq HyperdataRowContact where eq = genericEq
instance Show HyperdataRowContact where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataRowContact
derive newtype instance JSON.WriteForeign HyperdataRowContact


newtype 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
                   }
147
derive instance Generic HyperdataContact _
148 149 150 151
instance Eq HyperdataContact where eq = genericEq
instance Show HyperdataContact where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataContact
derive newtype instance JSON.WriteForeign HyperdataContact
152 153

-------
154 155 156 157 158 159 160
newtype ContactWho =
  ContactWho { id        :: Maybe String
             , firstName :: Maybe String
             , lastName  :: Maybe String
             , keywords  :: Array String
             , freetags  :: Array String
             }
161
derive instance Generic ContactWho _
162 163 164 165
instance Eq ContactWho where eq = genericEq
instance Show ContactWho where show = genericShow
derive newtype instance JSON.ReadForeign ContactWho
derive newtype instance JSON.WriteForeign ContactWho
166 167


168 169 170
newtype ContactWhere =
  ContactWhere { organization :: Array String
               , labTeamDepts :: Array String
arturo's avatar
arturo committed
171

172
               , role         :: Maybe String
173

174 175 176
               , office       :: Maybe String
               , country      :: Maybe String
               , city         :: Maybe String
177

178
               , touch        :: Maybe ContactTouch
179

180 181 182
               , entry        :: Maybe String
               , exit         :: Maybe String
               }
183
derive instance Generic ContactWhere _
184 185 186 187 188 189 190 191 192 193 194
instance Eq ContactWhere where eq = genericEq
instance Show ContactWhere where show = genericShow
derive newtype instance JSON.ReadForeign ContactWhere
derive newtype instance JSON.WriteForeign ContactWhere


newtype ContactTouch =
 ContactTouch { mail   :: Maybe String
               , phone :: Maybe String
               , url   :: Maybe String
               }
195
derive instance Generic ContactTouch _
196 197 198 199
instance Eq ContactTouch where eq = genericEq
instance Show ContactTouch where show = genericShow
derive newtype instance JSON.ReadForeign ContactTouch
derive newtype instance JSON.WriteForeign ContactTouch