umbraco / Umbraco.Cms.Integrations

MIT License
36 stars 21 forks source link

Algolia indexes only root (Homepage) #149

Closed diger74 closed 10 months ago

diger74 commented 10 months ago

Umbraco version: 12.3.0 Algolia integration package version: 1.5.0

For some reason the content of my custom content type pages (Case Study Details Page) is not indexed into Algolia, the log says "indexed 0 items", although there are 6 pages in the CMS tree.

What I have discovered in the code while investigating this issue:

    using (UmbracoContextReference contextReference = this._umbracoContextFactory.EnsureUmbracoContext())
    {
        // contentType here is not null, all is ok
        var contentType = contextReference.UmbracoContext.Content.GetContentType("caseStudyDetailsPage");

        // this returns 0 items, this method is used by Algolia integration package
        var byContentType = contextReference.UmbracoContext.Content.GetByContentType(contentType)
            .ToList();

        // this returns 6 case study items, although this is exactly the same code as in GetByContentType() method
        var fromRootByContentType = contextReference.UmbracoContext.Content.GetAtRoot()
            .SelectMany(x => x.DescendantsOrSelf(_variationContextAccessor!))
            .Where(x => x.ContentType.Id == contentType.Id)
            .ToList();
    }

For some reason unknown .GetByContentType() method, which is used inside Algolia integration package, returns 0 items and therefore there's nothing to send to Algolia.

However, when I call .GetAtRoot().SelectMany(..).Where(..), which is exactly the same code as in .GetByContentType() method, it returns all my 6 case study items with no issues.


This item has been added to our backlog AB#34636

diger74 commented 10 months ago

@acoumb a bit more context on this issue: this happens when I create a new index having some content in the CMS already. When the index is created (originally with 0 items), and I start adding or amending new pages (e.g. case studies in my example) - those items start appearing in Algolia once published in Umbraco.

I suppose the main problem is with the way the content is fetched for the full index rebuild, once individual items publish notifications are synched into Algolia with no issues.

acoumb commented 10 months ago

Hi @diger74 ,

I've been trying to replicate your issue, but without any luck; so I've recorded this demo based on details you've provided, maybe you can spot something I'm doing different.

Thank you, Adrian

diger74 commented 10 months ago

Hi @acoumb,

This is likely linked with this PR https://github.com/umbraco/Umbraco.Cms.Integrations/pull/153 Apologize, I didn't mention in my original post, that my content types used in the test were composed of other content types. As mentioned in the referenced PR this might be the issue.

acoumb commented 10 months ago

Hi @diger74 ,

Please update to the most recent version of Algolia and use this PR as guidance for working with custom converters.

Regards, Adrian