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 NamedFieldPuns #-}
18 module Gargantext.Text.Search where
20 import Data.SearchEngine
24 -- Usefull to use stopwords
25 -- import Data.Set (Set)
26 -- import qualified Data.Set as Set
27 import Data.Text (Text)
29 import Gargantext.Prelude
30 import Gargantext.Text.Terms.Mono (monoTexts)
31 import Gargantext.Text.Terms.Mono.Stem as ST
32 import Gargantext.Text.Corpus.Parsers.CSV
36 type DocSearchEngine = SearchEngine
42 data DocField = TitleField
44 deriving (Eq, Ord, Enum, Bounded, Ix, Show)
46 initialDocSearchEngine :: DocSearchEngine
47 initialDocSearchEngine =
48 initSearchEngine docSearchConfig defaultSearchRankParameters
50 docSearchConfig :: SearchConfig CsvGargV3 DocId DocField NoFeatures
53 documentKey = d_docId,
54 extractDocumentTerms = extractTerms,
55 transformQueryTerm = normaliseQueryToken,
56 documentFeatureValue = const noFeatures
59 extractTerms :: CsvGargV3 -> DocField -> [Text]
60 extractTerms doc TitleField = monoTexts (d_title doc)
61 extractTerms doc AbstractField = monoTexts (d_abstract doc)
63 normaliseQueryToken :: Text -> DocField -> Text
64 normaliseQueryToken tok =
65 let tokStem = ST.stem ST.EN
66 in \field -> case field of
67 TitleField -> tokStem tok
68 AbstractField -> tokStem tok
70 defaultSearchRankParameters :: SearchRankParameters DocField NoFeatures
71 defaultSearchRankParameters =
72 SearchRankParameters {
76 paramFeatureWeights = noFeatures,
77 paramFeatureFunctions = noFeatures,
78 paramResultsetSoftLimit = 2000,
79 paramResultsetHardLimit = 4000,
80 paramAutosuggestPrefilterLimit = 500,
81 paramAutosuggestPostfilterLimit = 500
87 paramB :: DocField -> Float
88 paramB TitleField = 0.9
89 paramB AbstractField = 0.5
91 paramFieldWeights :: DocField -> Float
92 paramFieldWeights TitleField = 20
93 paramFieldWeights AbstractField = 5