Commit 3a6b2629 authored by Fabien Maniere's avatar Fabien Maniere

Merge branch '630-dev-search-api-improvements' into 'dev'

[search] small refactoring of the search API

See merge request !441
parents e3a333b8 949c4225
Pipeline #7876 passed with stages
in 50 minutes and 57 seconds
......@@ -24,11 +24,13 @@ import Gargantext.API.Prelude (IsGargServer)
import Gargantext.API.Routes.Named.Search qualified as Named
import Gargantext.API.Search.Types (SearchQuery(..), SearchResult(..), SearchResultTypes(..), SearchType(..))
import Gargantext.Core.Text.Corpus.Query (RawQuery (..), parseQuery)
import Gargantext.Core.Types.Query (Limit, Offset)
import Gargantext.Core.Types.Search (toRow)
import Gargantext.Database.Action.Flow.Pairing (isPairedWith)
import Gargantext.Database.Action.Search (searchInCorpus, searchInCorpusWithContacts)
import Gargantext.Database.Admin.Types.Node (NodeId, NodeType(..))
import Gargantext.Database.Prelude
import Gargantext.Database.Query.Facet (OrderBy)
import Gargantext.Prelude
import Gargantext.System.Logging (logLocM, LogLevel(..))
import Servant.Server.Generic (AsServerT)
......@@ -38,26 +40,32 @@ import Servant.Server.Generic (AsServerT)
-- TODO-EVENTS: No event, this is a read-only query.
-- | Api search function
api :: IsGargServer env err m => NodeId -> Named.SearchAPI SearchResult (AsServerT m)
api nId = Named.SearchAPI $ \query o l order -> case query of
(SearchQuery rawQuery SearchDoc) -> case parseQuery rawQuery of
Left err -> pure $ SearchResult $ SearchNoResult (T.pack err)
Right q -> do
$(logLocM) DEBUG $ T.pack "New search started with query = " <> (getRawQuery rawQuery)
SearchResult <$> SearchResultDoc
<$> map (toRow nId)
<$> runDBQuery (searchInCorpus nId False q o l order)
(SearchQuery rawQuery SearchContact) -> case parseQuery rawQuery of
Left err -> pure $ SearchResult $ SearchNoResult (T.pack err)
Right q -> runDBQuery $ do
-- printDebug "isPairedWith" nId
aIds <- isPairedWith nId NodeAnnuaire
-- TODO if paired with several corpus
case head aIds of
Nothing -> pure $ SearchResult
$ SearchNoResult "[G.A.Search] pair corpus with an Annuaire"
Just aId -> SearchResult
<$> SearchResultContact
<$> map (toRow aId)
<$> searchInCorpusWithContacts nId aId q o l order
(SearchQuery _q SearchDocWithNgrams) -> panicTrace "unimplemented"
api nId = Named.SearchAPI { searchEp = searchEp nId }
searchEp :: IsGargServer env err m
=> NodeId
-> SearchQuery
-> Maybe Offset
-> Maybe Limit
-> Maybe OrderBy
-> m SearchResult
searchEp nId (SearchQuery rawQuery SearchDoc) o l order = case parseQuery rawQuery of
Left err -> pure $ SearchResult $ SearchNoResult (T.pack err)
Right q -> do
$(logLocM) DEBUG $ T.pack "New search started with query = " <> getRawQuery rawQuery
(SearchResult <$> SearchResultDoc) . map (toRow nId)
<$> runDBQuery (searchInCorpus nId False q o l order)
searchEp nId (SearchQuery rawQuery SearchContact) o l order = case parseQuery rawQuery of
Left err -> pure $ SearchResult $ SearchNoResult (T.pack err)
Right q -> runDBQuery $ do
-- printDebug "isPairedWith" nId
aIds <- isPairedWith nId NodeAnnuaire
-- TODO if paired with several corpus
case head aIds of
Nothing -> pure $ SearchResult
$ SearchNoResult "[G.A.Search] pair corpus with an Annuaire"
Just aId -> (SearchResult
<$> SearchResultContact) . map (toRow aId)
<$> searchInCorpusWithContacts nId aId q o l order
searchEp _nId (SearchQuery _q SearchDocWithNgrams) _o _l _order = panicTrace "not implemented"
......@@ -14,7 +14,8 @@ Portability : POSIX
{-# LANGUAGE LambdaCase #-}
module Gargantext.Database.Action.Search (
searchInCorpus
queryToTsSearch
, searchInCorpus
, searchInCorpusWithContacts
, searchCountInCorpus
, searchInCorpusWithNgrams
......
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