private IEnumerable <ITweetDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string           query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var              currentResult = GetTweetDTOsFromSearch(query);
            List <ITweetDTO> result        = currentResult;

            while (result.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (currentResult.IsEmpty())
                {
                    // If Twitter does not any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - result.Count, 100);
                query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetTweetDTOsFromSearch(query);
                result.AddRange(currentResult);
            }

            return(result);
        }
Example #2
0
        private List <ISearchResultsDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(tweetSearchParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);

            var currentResult = GetSearchTweetResultsFromQuery(query);

            if (currentResult == null)
            {
                return(new List <ISearchResultsDTO>());
            }

            var result = new List <ISearchResultsDTO> {
                currentResult
            };
            var tweets      = currentResult.TweetDTOs;
            var totalTweets = currentResult.TweetDTOs.ToList();

            while (totalTweets.Count < tweetSearchParameters.MaximumNumberOfResults)
            {
                if (tweets.IsEmpty())
                {
                    // If Twitter does not have any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(tweets);
                searchParameter.MaxId = oldestTweetId - 1;
                searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - totalTweets.Count, 100);
                query         = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
                currentResult = GetSearchTweetResultsFromQuery(query);

                if (currentResult == null)
                {
                    break;
                }

                tweets = currentResult.TweetDTOs;
                totalTweets.AddRange(tweets);
                result.Add(currentResult);
            }

            return(result);
        }
Example #3
0
        private IEnumerable <string> SearchTweetsRecursively(ISearchTweetsParameters searchTweetsParameters)
        {
            var searchParameter = _searchQueryHelper.CloneTweetSearchParameters(searchTweetsParameters);

            searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

            string query      = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            var    json       = GetJsonResultFromQuery(query);
            var    jsonResult = new List <string> {
                json
            };
            var currentResult  = _searchQueryHelper.GetTweetsFromJsonResponse(json);
            var tweetDTOResult = currentResult;

            if (tweetDTOResult == null)
            {
                return(jsonResult);
            }

            while (tweetDTOResult.Count < searchTweetsParameters.MaximumNumberOfResults)
            {
                if (currentResult.IsNullOrEmpty())
                {
                    // If Twitter does not any result left, stop the search
                    break;
                }

                var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
                searchParameter.MaxId = oldestTweetId - 1;

                searchParameter.MaximumNumberOfResults = Math.Min(searchTweetsParameters.MaximumNumberOfResults - tweetDTOResult.Count, 100);
                query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);

                json = GetJsonResultFromQuery(query);

                if (json != null)
                {
                    jsonResult.Add(json);
                }

                currentResult = _searchQueryHelper.GetTweetsFromJsonResponse(json);
                tweetDTOResult.AddRangeSafely(currentResult);
            }

            return(jsonResult);
        }