/// <summary>
 /// Inits keys.
 /// </summary>
 private void InitKeys()
 {
     ArticlesHubDictionary = new Dictionary <string, ArticlesHub>();
     foreach (var letter1 in Letters)
     {
         foreach (var letter2 in Letters)
         {
             foreach (var letter3 in Letters)
             {
                 var threeLetters = letter1 + letter2 + letter3;
                 ArticlesHubDictionary[threeLetters] = new ArticlesHub();
             }
         }
     }
     ArticlesHubDictionary[REST] = new ArticlesHub();
 }
        /// <summary>
        /// Searches for a specific list of articles containing key words in abstract.
        /// </summary>
        /// <param name="keyWords"></param>
        /// <returns></returns>
        public Articles SearchArticles(string phraseToSearch)
        {
            var result        = new Articles();
            var smallKeyWords = phraseToSearch
                                .ToLower()
                                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                .Distinct()
                                .ToList();

            var  commonArticles            = new Articles();
            bool haveCommonArticlesBeenSet = false;

            // First check if a key word is found or not.
            foreach (var keyWord in smallKeyWords)
            {
                if (keyWord.Length < 3)
                {
                    // no intereset in short words
                    continue;
                }
                var keyWordIndex = keyWord.ToLower().Substring(0, 3);
                if (!ArticlesHubDictionary.ContainsKey(keyWordIndex))
                {
                    keyWordIndex = REST;
                }

                // now look at contents of index file
                var articlesHub = new ArticlesHub();
                var indexPath   = Path.Combine(_outputDirectory, "index", $"index_{keyWordIndex}.bin.zip");
                if (!File.Exists(indexPath))
                {
                    continue;
                }

                articlesHub.Deserialize(indexPath);

                // now search for keywords in this hub
                if (articlesHub.KeyWordsDictionary.Dictionary.Keys.Contains(keyWord))
                {
                    var articlesFound      = articlesHub.KeyWordsDictionary.Dictionary[keyWord];
                    var commonArticlesCopy = new Articles();

                    if (haveCommonArticlesBeenSet)
                    {
                        var commonArticlesHashSet = commonArticles
                                                    .List.Select(x => Zipper.Unzip(x.ZippedJsonFileName.ToByteArray()))
                                                    .ToHashSet();

                        foreach (var articleFound in articlesFound.List)
                        {
                            var articleFoundFileName = Zipper.Unzip(articleFound.ZippedJsonFileName.ToByteArray());
                            var hasCommonArticle     = commonArticlesHashSet.Contains(articleFoundFileName);
                            if (hasCommonArticle)
                            {
                                var isTitleEmpty =
                                    String.IsNullOrWhiteSpace(Zipper.Unzip(articleFound.ZippedTitle.ToByteArray()));
                                commonArticlesCopy.List.Add(articleFound);
                            }
                        }

                        commonArticles = commonArticlesCopy;
                    }
                    else
                    {
                        var nonEmptyTitlesList = articlesFound.List
                                                 .Where(x => !String.IsNullOrWhiteSpace(Zipper.Unzip(x.ZippedTitle.ToByteArray())));
                        commonArticles.List.AddRange(nonEmptyTitlesList);
                        haveCommonArticlesBeenSet = true;
                    }
                }
            }

            return(commonArticles);
        }