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

3 4 5
import Gargantext.Prelude

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

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

22
derive instance Generic SearchType _
23 24 25 26
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
27 28
------------------------------------------------------------------------

29
newtype SearchQuery = SearchQuery { query :: Array String, expected :: SearchType }
30
derive instance Generic SearchQuery _
31 32 33 34 35
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
36 37

------------------------------------------------------------------------
38
------------------------------------------------------------------------
39
newtype SearchResult = SearchResult { result :: SearchResultTypes }
40
derive instance Generic SearchResult _
41 42 43 44 45
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
46

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

60
------------------------------------------------------------------------
61
newtype Document =
62 63 64
  Document { id         :: Int
           , created    :: String
           , title      :: String
65
           , hyperdata  :: HyperdataRowDocument
66 67
           , category   :: Int
           , score      :: Int
68
           }
69
derive instance Generic Document _
70 71 72 73 74
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
75 76

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

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

------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
108
newtype Contact =
109 110 111 112
  Contact  { c_id         :: Int
           , c_created    :: String
           , c_hyperdata  :: HyperdataRowContact
           , c_score      :: Int
113
           , c_annuaireId :: Int
114 115
           }

116
derive instance Generic Contact _
117 118 119 120 121 122 123 124 125
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
126
                      }
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
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
                   }
144
derive instance Generic HyperdataContact _
145 146 147 148
instance Eq HyperdataContact where eq = genericEq
instance Show HyperdataContact where show = genericShow
derive newtype instance JSON.ReadForeign HyperdataContact
derive newtype instance JSON.WriteForeign HyperdataContact
149 150

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


165 166 167 168 169
newtype ContactWhere =
  ContactWhere { organization :: Array String
               , labTeamDepts :: Array String
                 
               , role         :: Maybe String
170

171 172 173
               , office       :: Maybe String
               , country      :: Maybe String
               , city         :: Maybe String
174

175
               , touch        :: Maybe ContactTouch
176

177 178 179
               , entry        :: Maybe String
               , exit         :: Maybe String
               }
180
derive instance Generic ContactWhere _
181 182 183 184 185 186 187 188 189 190 191
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
               }
192
derive instance Generic ContactTouch _
193 194 195 196
instance Eq ContactTouch where eq = genericEq
instance Show ContactTouch where show = genericShow
derive newtype instance JSON.ReadForeign ContactTouch
derive newtype instance JSON.WriteForeign ContactTouch
197