Exemplo n.º 1
0
        /// <summary>
        /// The get articles by query.
        /// </summary>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <returns>
        /// The <see cref="ICollection{T}"/>.
        /// </returns>
        public ICollection <Article> GetArticlesByQuery(string query)
        {
            var words = FilteredText.GetWords(query); // Список слов запроса
            var tags  = words.Select(
                word => (from t in context.Tags
                         where string.Equals(t.Value, word, StringComparison.OrdinalIgnoreCase)
                         select t).FirstOrDefault()).Where(tag => tag != null)
                        .ToList();                               // Найденные теги для введенных слов
            var articleswithcoef = new List <WeightedArticle>(); // результирующая коллекция

            if (!tags.Any())
            {
                return(null);
            }
            {
                foreach (var tag in tags)
                {
                    var articles = (from a in context.ArticleTags where (a.Tag.Value == tag.Value) select a.Article)
                                   .ToList();

                    Parallel.ForEach(articles, article => { articleswithcoef.Add(GetWeightedArticle(article, tags)); });

                    foreach (var article in articles)
                    {
                        articleswithcoef.Add(GetWeightedArticle(article, tags));
                    }
                }
            }

            var currentArticle = (from a in articleswithcoef.OrderByDescending(p => p.T).DistinctBy(a => a.Article.Id)
                                  select a.Article).ToList();

            return(currentArticle);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The get clean all words.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerable{T}"/>.
        /// </returns>
        private IEnumerable <string> GetCleanAllWords()
        {
            var words = FilteredText.GetWords(Article.Text);

            return(words);
        }