Commit df677e55 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Restore union of terms in buildNgramsLists

parent da2c151a
Pipeline #7987 passed with stages
in 55 minutes and 13 seconds
...@@ -30,7 +30,7 @@ import Data.Text qualified as T ...@@ -30,7 +30,7 @@ import Data.Text qualified as T
import Data.Tuple.Extra (both) import Data.Tuple.Extra (both)
import Gargantext.API.Ngrams (NgramsRepoElement) import Gargantext.API.Ngrams (NgramsRepoElement)
import Gargantext.API.Ngrams.Tools (getNodeStory) import Gargantext.API.Ngrams.Tools (getNodeStory)
import Gargantext.API.Ngrams.Types (NgramsElement, NgramsTerm(..), ngramsElementFromRepo, ne_ngrams, ne_list) import Gargantext.API.Ngrams.Types (NgramsElement(..), ngramsElementFromRepo, NgramsTerm(..), ne_ngrams, ne_list)
import Gargantext.Core.NodeStory import Gargantext.Core.NodeStory
import Gargantext.Core.Text (size) import Gargantext.Core.Text (size)
import Gargantext.Core.Text.List.Group ( toGroupedTree, setScoresWithMap, toGroupedTreeInstitutes ) import Gargantext.Core.Text.List.Group ( toGroupedTree, setScoresWithMap, toGroupedTreeInstitutes )
...@@ -105,9 +105,7 @@ buildNgramsLists env user (nodeId, listId) mCid pref gp = do ...@@ -105,9 +105,7 @@ buildNgramsLists env user (nodeId, listId) mCid pref gp = do
-- such that if we run multiple searches the maplist will evolve organically. -- such that if we run multiple searches the maplist will evolve organically.
$(txLogLocM) DEBUG "Trying to fetch existing terms..." $(txLogLocM) DEBUG "Trying to fetch existing terms..."
let buildStrategy = toNgramsBuildStrategy pref let buildStrategy = toNgramsBuildStrategy pref
existingTerms <- case buildStrategy of existingTerms <- do
MergeWithExistingNgrams -> pure mempty
OverrideExistingNgrams -> do
archiveState <- getNodeStory env listId archiveState <- getNodeStory env listId
let (ngramsState :: Map NgramsType (Map NgramsTerm NgramsRepoElement)) = archiveState ^. a_state let (ngramsState :: Map NgramsType (Map NgramsTerm NgramsRepoElement)) = archiveState ^. a_state
let (ngramsState' :: Map.Map NgramsType (Map NgramsTerm NgramsElement)) = let (ngramsState' :: Map.Map NgramsType (Map NgramsTerm NgramsElement)) =
...@@ -120,7 +118,7 @@ buildNgramsLists env user (nodeId, listId) mCid pref gp = do ...@@ -120,7 +118,7 @@ buildNgramsLists env user (nodeId, listId) mCid pref gp = do
-- Combine the maplist just computed with the existing one (see #517). -- Combine the maplist just computed with the existing one (see #517).
let freshTerms = Map.unions $ ngTerms : instTerms : othersTerms let freshTerms = Map.unions $ ngTerms : instTerms : othersTerms
case buildStrategy of case buildStrategy of
MergeWithExistingNgrams -> pure freshTerms MergeWithExistingNgrams -> pure $ Map.unionWith merge freshTerms existingTerms
OverrideExistingNgrams -> pure $ Map.differenceWith diffy freshTerms existingTerms OverrideExistingNgrams -> pure $ Map.differenceWith diffy freshTerms existingTerms
newtype IndexedNgramsElement = IndexedNgramsElement { _IndexedNgramsElement :: NgramsElement } newtype IndexedNgramsElement = IndexedNgramsElement { _IndexedNgramsElement :: NgramsElement }
...@@ -138,6 +136,12 @@ diffy fresh existing = Just $ unwrap $ Set.toList $ Set.difference (wrap fresh) ...@@ -138,6 +136,12 @@ diffy fresh existing = Just $ unwrap $ Set.toList $ Set.difference (wrap fresh)
wrap = Set.fromList . map IndexedNgramsElement wrap = Set.fromList . map IndexedNgramsElement
unwrap = map _IndexedNgramsElement unwrap = map _IndexedNgramsElement
merge :: [NgramsElement] -> [NgramsElement] -> [NgramsElement]
merge fresh existing = unwrap $ Set.toList $ Set.union (wrap fresh) (wrap existing)
where
wrap = Set.fromList . map IndexedNgramsElement
unwrap = map _IndexedNgramsElement
_debugDumpExisting :: Map NgramsType [NgramsElement] -> Text _debugDumpExisting :: Map NgramsType [NgramsElement] -> Text
_debugDumpExisting mp = T.unlines $ map processIt $ Map.toList mp _debugDumpExisting mp = T.unlines $ map processIt $ Map.toList mp
where where
......
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