Commit 0fc58ba2 authored by Karen Konou's avatar Karen Konou

[Graph/phylo explorer] improve related doc search

parent 4df661c3
Pipeline #6474 passed with stages
in 19 minutes and 26 seconds
...@@ -4,7 +4,7 @@ module Gargantext.Components.GraphExplorer.Sidebar.DocList ...@@ -4,7 +4,7 @@ module Gargantext.Components.GraphExplorer.Sidebar.DocList
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array (catMaybes, head) import Data.Array (catMaybes, foldl, head)
import Data.Array as A import Data.Array as A
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Data.Map as Map import Data.Map as Map
...@@ -22,6 +22,7 @@ import Gargantext.Components.GraphExplorer.Types as GET ...@@ -22,6 +22,7 @@ import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Config (defaultFrontends) import Gargantext.Config (defaultFrontends)
import Gargantext.Config.REST (RESTError(..)) import Gargantext.Config.REST (RESTError(..))
import Gargantext.Ends (Frontends, url) import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.LinkHandler (useLinkHandler)
import Gargantext.Hooks.Loader (useLoaderEffect) import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Hooks.Session (useSession) import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Sigmax.Types as SigmaxT import Gargantext.Hooks.Sigmax.Types as SigmaxT
...@@ -173,6 +174,8 @@ docListCpt = here.component "main" cpt where ...@@ -173,6 +174,8 @@ docListCpt = here.component "main" cpt where
, state , state
} }
{ goToURL } <- useLinkHandler
-- | Effects -- | Effects
-- | -- |
...@@ -234,6 +237,16 @@ docListCpt = here.component "main" cpt where ...@@ -234,6 +237,16 @@ docListCpt = here.component "main" cpt where
_ _
= false = false
webSearch :: Array String -> (String -> Effect Unit) -> Effect Unit
webSearch q f = do
let url = foldl (\acc elem -> acc <> (elem <> "+")) "https://duckduckgo.com/?q=" q
f url
wikipediaSearch :: Array String -> (String -> Effect Unit) -> Effect Unit
wikipediaSearch q f = do
let url = foldl (\acc elem -> acc <> (elem <> "+")) "https://en.wikipedia.org/w/index.php?search=" q
f url
-- | Render -- | Render
-- | -- |
pure $ pure $
...@@ -243,11 +256,19 @@ docListCpt = here.component "main" cpt where ...@@ -243,11 +256,19 @@ docListCpt = here.component "main" cpt where
R.fragment R.fragment
[ [
R2.when (results == Seq.empty) $ R2.when (results == Seq.empty) $
H.div {}
B.caveat [
H.ul { className: "flex-row list-group vertical-align-middle" }
[ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.h6 {} [ H.text "No related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURL } ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURL } ]
]
, B.caveat
{} {}
[ [
H.text "Searching relevant document(s)" H.text "No document found in your corpus for your selected terms"
]
] ]
, ,
R2.when (not $ eq results Seq.empty) $ R2.when (not $ eq results Seq.empty) $
...@@ -257,8 +278,8 @@ docListCpt = here.component "main" cpt where ...@@ -257,8 +278,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group vertical-align-middle" } H.ul { className: "flex-row list-group vertical-align-middle" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.h6 {} [ H.text $ show (Seq.length results) <> " related documents" ] ] , H.li {} [ H.h6 {} [ H.text $ show (Seq.length results) <> " related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> pure unit} ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURL } ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> pure unit} ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURL } ]
] ]
, H.ul , H.ul
{ className: intercalate " " { className: intercalate " "
......
...@@ -4,6 +4,7 @@ module Gargantext.Components.PhyloExplorer.Sidebar.DocList ...@@ -4,6 +4,7 @@ module Gargantext.Components.PhyloExplorer.Sidebar.DocList
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array (foldl)
import Data.Array as A import Data.Array as A
import Data.Foldable (intercalate) import Data.Foldable (intercalate)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
...@@ -19,6 +20,7 @@ import Gargantext.Components.Search (SearchQuery(..), SearchType(..)) ...@@ -19,6 +20,7 @@ import Gargantext.Components.Search (SearchQuery(..), SearchType(..))
import Gargantext.Config (defaultFrontends) import Gargantext.Config (defaultFrontends)
import Gargantext.Config.REST (RESTError(..)) import Gargantext.Config.REST (RESTError(..))
import Gargantext.Ends (Frontends, url) import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.LinkHandler (useLinkHandler)
import Gargantext.Hooks.Loader (useLoaderEffect) import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Hooks.Session (useSession) import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.UpdateEffect (useUpdateEffect1') import Gargantext.Hooks.UpdateEffect (useUpdateEffect1')
...@@ -162,6 +164,8 @@ docListCpt = here.component "main" cpt where ...@@ -162,6 +164,8 @@ docListCpt = here.component "main" cpt where
, path: path' , path: path'
} }
{ goToURL } <- useLinkHandler
-- | Effects -- | Effects
-- | -- |
...@@ -220,6 +224,16 @@ docListCpt = here.component "main" cpt where ...@@ -220,6 +224,16 @@ docListCpt = here.component "main" cpt where
_ _
= false = false
webSearch :: Array String -> (String -> Effect Unit) -> Effect Unit
webSearch q f = do
let url = foldl (\acc elem -> acc <> (elem <> "+")) "https://duckduckgo.com/?q=" q
f url
wikipediaSearch :: Array String -> (String -> Effect Unit) -> Effect Unit
wikipediaSearch q f = do
let url = foldl (\acc elem -> acc <> (elem <> "+")) "https://en.wikipedia.org/w/index.php?search=" q
f url
-- | Render -- | Render
-- | -- |
pure $ pure $
...@@ -229,12 +243,20 @@ docListCpt = here.component "main" cpt where ...@@ -229,12 +243,20 @@ docListCpt = here.component "main" cpt where
R.fragment R.fragment
[ [
R2.when (results == Seq.empty) $ R2.when (results == Seq.empty) $
H.div {}
B.caveat [
H.ul { className: "flex-row list-group vertical-align-middle" }
[ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.h6 {} [ H.text "No related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURL} ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURL} ]
]
, B.caveat
{} {}
[ [
H.text "No document found in your corpus for your selected terms" H.text "No document found in your corpus for your selected terms"
] ]
]
, ,
R2.when (not $ eq results Seq.empty) $ R2.when (not $ eq results Seq.empty) $
H.div {} H.div {}
...@@ -242,8 +264,8 @@ docListCpt = here.component "main" cpt where ...@@ -242,8 +264,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group vertical-align-middle" } H.ul { className: "flex-row list-group vertical-align-middle" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.h6 {} [ H.text $ show (Seq.length results) <> " related documents" ] ] , H.li {} [ H.h6 {} [ H.text $ show (Seq.length results) <> " related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> pure unit} ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURL} ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> pure unit} ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURL} ]
] ]
, ,
H.ul H.ul
......
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