public IndexResponse IndexTopic(SearchTopic searchTopic)
        {
            var tenantID = _tenantService.GetTenant();

            if (string.IsNullOrWhiteSpace(tenantID))
            {
                tenantID = "-";
            }
            searchTopic.TenantID = tenantID;
            var indexResult = _client.IndexDocument(searchTopic);

            return(indexResult);
        }
Пример #2
0
        public IIndexResponse IndexTopic(SearchTopic searchTopic)
        {
            var indexResult = _client.IndexDocument(searchTopic);

            return(indexResult);
        }
Пример #3
0
        public void DoIndex(int topicID, string tenantID)
        {
            var topic = _topicService.Get(topicID).Result;

            if (topic == null)
            {
                return;
            }

            _elasticSearchClientWrapper.VerifyIndexCreate();

            var posts = _postService.GetPosts(topic, false).Result;

            if (posts.Count == 0)
            {
                throw new Exception($"TopicID {topic.TopicID} has no posts to index.");
            }
            var firstPost = _textParsingService.ClientHtmlToForumCode(posts[0].FullText);

            firstPost = _textParsingService.RemoveForumCode(firstPost);
            posts.RemoveAt(0);
            var parsedPosts = posts.Select(x =>
            {
                var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                parsedText     = _textParsingService.RemoveForumCode(parsedText);
                return(parsedText);
            }).ToArray();
            var searchTopic = new SearchTopic
            {
                Id            = $"{tenantID}-{topic.TopicID}",
                TopicID       = topic.TopicID,
                ForumID       = topic.ForumID,
                Title         = topic.Title,
                LastPostTime  = topic.LastPostTime,
                StartedByName = topic.StartedByName,
                Replies       = topic.ReplyCount,
                Views         = topic.ViewCount,
                IsClosed      = topic.IsClosed,
                IsPinned      = topic.IsPinned,
                UrlName       = topic.UrlName,
                LastPostName  = topic.LastPostName,
                FirstPost     = firstPost,
                Posts         = parsedPosts,
                TenantID      = tenantID
            };

            try
            {
                var indexResult = _elasticSearchClientWrapper.IndexTopic(searchTopic);
                if (indexResult.Result != Result.Created && indexResult.Result != Result.Updated)
                {
                    _errorLog.Log(indexResult.OriginalException, ErrorSeverity.Error, $"Debug information: {indexResult.DebugInformation}");
                    // TODO: Replace this with some Polly or get real about queues/deadletter
                    _topicService.QueueTopicForIndexing(topic.TopicID);
                }
            }
            catch (Exception exc)
            {
                _errorLog.Log(exc, ErrorSeverity.Error);
                // TODO: Replace this with some Polly or get real about queues/deadletter
                _topicService.QueueTopicForIndexing(topic.TopicID);
            }
        }
Пример #4
0
        public void DoIndex(int topicID, string tenantID, bool isForRemoval)
        {
            if (isForRemoval)
            {
                RemoveIndex(topicID, tenantID);
                return;
            }

            var topic = _topicService.Get(topicID).Result;

            if (topic == null)
            {
                return;
            }

            _elasticSearchClientWrapper.VerifyIndexCreate();

            var posts = _postService.GetPosts(topic, false).Result;

            if (posts.Count == 0)
            {
                throw new Exception($"TopicID {topic.TopicID} has no posts to index.");
            }
            var firstPost = _textParsingService.ClientHtmlToForumCode(posts[0].FullText);

            firstPost = _textParsingService.RemoveForumCode(firstPost);
            posts.RemoveAt(0);
            var parsedPosts = posts.Select(x =>
            {
                var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                parsedText     = _textParsingService.RemoveForumCode(parsedText);
                return(parsedText);
            }).ToArray();
            var searchTopic = new SearchTopic
            {
                Id            = $"{tenantID}-{topic.TopicID}",
                TopicID       = topic.TopicID,
                ForumID       = topic.ForumID,
                Title         = topic.Title,
                LastPostTime  = topic.LastPostTime,
                StartedByName = topic.StartedByName,
                Replies       = topic.ReplyCount,
                Views         = topic.ViewCount,
                IsClosed      = topic.IsClosed,
                IsPinned      = topic.IsPinned,
                UrlName       = topic.UrlName,
                LastPostName  = topic.LastPostName,
                FirstPost     = firstPost,
                Posts         = parsedPosts,
                TenantID      = tenantID
            };

            try
            {
                var policy = Polly.Policy.HandleResult <IndexResponse>(x => !x.IsValid)
                             .WaitAndRetry(new[]
                {
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(30)
                }, (exception, timeSpan) => {
                    _errorLog.Log(exception.Result.OriginalException, ErrorSeverity.Error, $"Retry after {timeSpan.Seconds}: {exception.Result.DebugInformation}");
                });
                policy.Execute(() =>
                {
                    var indexResult = _elasticSearchClientWrapper.IndexTopic(searchTopic);
                    return(indexResult);
                });
            }
            catch (Exception exc)
            {
                _errorLog.Log(exc, ErrorSeverity.Error);
            }
        }