/// <summary>
        /// To the news brief.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>NewsBrief.</returns>
        public static NewsBrief ToNewsBrief(NewsStream input)
        {
            var result = new NewsBrief();

            result.ClusterId0   = input.ClusterId0;
            result.Description  = input.NewsArticleDescription;
            result.Id           = input.Id;
            result.Source       = input.NewsSource;
            result.ThumbnailUrl = string.IsNullOrEmpty(input.GoodDominantImageURL)
                                      ? DEFAULTNEWSURL
                                      : input.GoodDominantImageURL;
            result.Title       = input.Title;
            result.Url         = input.Url;
            result.CreatedTime = input.BuildTime;
            return(result);
        }
        /// <summary>
        /// Gets the news list and news sentiments.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="AnalysisTime">The analysis time.</param>
        /// <returns>List&lt;NewsBrief&gt;.</returns>
        public List <NewsBrief> GetNewsListAndNewsSentiments(CustomerFilters filter, DateTime AnalysisTime)
        {
            using (var context = ContextFactory.GetContext(this.currentUser.GetProfile()))
            {
                var keyword   = this.indexHelper.BuildPatternFromFilter(filter);
                var startTime = AnalysisTime - TimeSpan.FromDays(7);
                var endTime   = AnalysisTime;

                // Only GetNegative
                string sqlCmd =
                    $@"select ClusterId0,BuildTime,Url,Title into #FilterTable   from [dbo].[{this.newsStreamTableName}]
                where contains(keywords,{{0}}) and
                 date between {{1}} and {{2}}
               
                
                    SELECT  * INTO #SentimentTable
                    from 
                    (
                 select *  
                     from [dbo].[{this
                        .newsSentimentsTableName}]  
                                      
                     where ClusterId0 in (SELECT ClusterId0 from #FilterTable)    
                    
                 ) T    
                 order by vote desc  
                   
                 SELECT T1.BuildTime as NewsDate, T1.Url, T1.Title, T2.Attitude, T2.Content, T2.Vote, T2.Date  
                 FROM  
                 #FilterTable T1 inner join #SentimentTable T2  
                 ON T1.ClusterId0=T2.ClusterId0  
                   
 delete #FilterTable WHERE exists 
                (select * from #FilterTable T2 where T2.ClusterId0 = #FilterTable.ClusterId0 )

                 drop table #FilterTable  
                 drop table #SentimentTable";

                object[] parameters = { keyword, startTime, endTime };

                var dataresult = ExecuteStoreQuery <SentimentRowData>(context, sqlCmd, parameters);

                var result = new List <NewsBrief>();
                foreach (var dbrow in dataresult)
                {
                    //if two comments is to the same news, only keep one
                    var samenews = false;
                    foreach (var news in result)
                    {
                        if (dbrow.Title.Equals(news.Title, StringComparison.InvariantCultureIgnoreCase))
                        {
                            samenews = true;
                            break;
                        }
                    }
                    if (samenews)
                    {
                        continue;
                    }

                    var item = new NewsBrief
                    {
                        CreatedTime      = dbrow.NewsDate,
                        Url              = dbrow.Url,
                        Title            = dbrow.Title,
                        PositiveComments = new List <CommentsSentiments>(),
                        NegativeComments = new List <CommentsSentiments>()
                    };

                    var sentiments = new CommentsSentiments
                    {
                        Attitute = dbrow.Attitude,
                        Content  = dbrow.Content,
                        Vote     = dbrow.Vote,
                        Date     = dbrow.Date
                    };

                    if (dbrow.Attitude.Equals("Negative", StringComparison.InvariantCultureIgnoreCase))
                    {
                        item.NegativeComments.Add(sentiments);
                    }
                    else if (dbrow.Attitude.Equals("Positive", StringComparison.InvariantCultureIgnoreCase))
                    {
                        item.PositiveComments.Add(sentiments);
                    }

                    result.Add(item);
                }

                return(result);
            }
        }