2 Module : Gargantext.Text.Search
3 Description : All parsers of Gargantext in one file.
4 Copyright : (c) CNRS, 2017 - present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 This search Engine is first made to clean CSV file according to a query.
12 Starting from this model, a specific Gargantext engine will be made
13 (using more metrics scores/features).
16 {-# LANGUAGE NoImplicitPrelude #-}
17 {-# LANGUAGE OverloadedStrings, NamedFieldPuns #-}
19 module Gargantext.Text.Search where
21 import Data.SearchEngine
25 -- Usefull to use stopwords
26 -- import Data.Set (Set)
27 -- import qualified Data.Set as Set
28 import Data.Text (Text)
30 import Gargantext.Prelude
31 import Gargantext.Text.Terms.Mono (monoTexts)
32 import Gargantext.Text.Terms.Mono.Stem as ST
33 import Gargantext.Text.Parsers.CSV
37 type DocSearchEngine = SearchEngine
43 data DocField = TitleField
45 deriving (Eq, Ord, Enum, Bounded, Ix, Show)
47 initialDocSearchEngine :: DocSearchEngine
48 initialDocSearchEngine =
49 initSearchEngine docSearchConfig defaultSearchRankParameters
51 docSearchConfig :: SearchConfig CsvGargV3 DocId DocField NoFeatures
54 documentKey = d_docId,
55 extractDocumentTerms = extractTerms,
56 transformQueryTerm = normaliseQueryToken,
57 documentFeatureValue = const noFeatures
60 extractTerms :: CsvGargV3 -> DocField -> [Text]
61 extractTerms doc TitleField = monoTexts (d_title doc)
62 extractTerms doc AbstractField = monoTexts (d_abstract doc)
64 normaliseQueryToken :: Text -> DocField -> Text
65 normaliseQueryToken tok =
66 let tokStem = ST.stem ST.EN
67 in \field -> case field of
68 TitleField -> tokStem tok
69 AbstractField -> tokStem tok
71 defaultSearchRankParameters :: SearchRankParameters DocField NoFeatures
72 defaultSearchRankParameters =
73 SearchRankParameters {
77 paramFeatureWeights = noFeatures,
78 paramFeatureFunctions = noFeatures,
79 paramResultsetSoftLimit = 2000,
80 paramResultsetHardLimit = 4000,
81 paramAutosuggestPrefilterLimit = 500,
82 paramAutosuggestPostfilterLimit = 500
88 paramB :: DocField -> Float
89 paramB TitleField = 0.9
90 paramB AbstractField = 0.5
92 paramFieldWeights :: DocField -> Float
93 paramFieldWeights TitleField = 20
94 paramFieldWeights AbstractField = 5