Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stefan Stankovic 12 posts 119 karma points
    Jan 17, 2024 @ 11:10
    Stefan Stankovic
    0

    How to republish the entire website contents to include a new property to Examine index

    All content pages inherit the Search composition. From the beginning, the composition had Search keywords. We created the whole website and keywords exist in the index. Now we need to add new properties to the composition ("topRated" and "hideFromSearch") but those properties don't exist in the index so the index doesn't return the result.

    My index query:

    var criteria = searcher.CreateQuery(defaultOperation: BooleanOperation.And);
    
            var query = criteria
                .GroupedOr(new[]
                {
                    Constants.Indexes.HideFromSearch.ToCultureSearchField(culture),
                    Constants.Indexes.HideFromSearch
                }, "0")
                .AndNot(x => x.Field(ExamineFieldNames.CategoryFieldName, IndexTypes.Media));
                .GroupedOr(new string[] { Constants.Media.TopRatedProperty, Constants.Media.TopRatedProperty.ToCultureSearchField(culture) }, "1")
    

    I tried to write some code to republish all pages but it doesn't work:

    public string UpdateContent(int? homePageId, string culture = "de-AT")
        {
            if (!homePageId.HasValue)
            {
                return "Home Page is required!";
            }
    
            var cache = _context.GetRequiredUmbracoContext();
            if (cache?.Content == null)
            {
                return "Can't resolve the Umbraco context.";
            }
    
            RePublishPages(homePageId.Value, culture, cache);
    
            return "Ok";
        }
    
        private void RePublishPages(int parentId, string culture, IUmbracoContext umbracoContext)
        {
            if (umbracoContext?.Content is null)
            {
                return;
            }
    
            var page = umbracoContext.Content
                .GetById(parentId);
    
            if (page is null)
            {
                return;
            }
    
            if (page.Children.Any())
            {
                foreach (var child in page.Children)
                {
                    RePublishPages(child.Id, culture, umbracoContext);
                }
            }
    
            var content = _contentService.GetById(page.Id);
            if (content is not null && content.Published && content.PublishedCultures.Any(x => x.Equals(culture, StringComparison.OrdinalIgnoreCase)))
            {
                _contentService.SaveAndPublish(content, culture);
            }
        }
    

    EDIT: Rebuild index doesn't fix the problem

  • Simon Napper 84 posts 254 karma points
    Jan 29, 2024 @ 15:47
    Simon Napper
    0

    How are you setting up your index?

    Do you specify specific fields to be included or is it set to grab all the fields?

Please Sign in or register to post replies

Write your reply to:

Draft