Try our conversational search powered by Generative AI!

Optimizely Content Search API and Search & Navigation Package Conflict

Vote:
 

Hi,

Context:
Our application utilizes Optimizely's Headless CMS with Content Delivery API version 2.21.1 and Content Search API version 2.21.1. The API calls for Content Delivery APIs functions correctly as expected.However, Content Search API calls always returns count 0 even if the queries passed to the search api calls has records.

Custom Modification:
To support the multi-site nature of our application, I introduced a custom modification by adding a new property named "Enable Content Delivery API."
This property, when enabled for a site, restricts responses to specific sites, ensuring the desired JSON response (ContentApiModel) is returned. 
Additionally, setting MultiSiteFiltering(true) ensures that only the queried site is included in the response. If unchecked, a 404 error is returned.

Here's the custom code & config entry  added for the same:

<add key="episerver:contentdeliverysearch:maphttpattributeroutes" value="false" />​
[ServiceConfiguration(typeof(IContentModelMapper), Lifecycle = ServiceInstanceScope.Singleton)]
    public class CustomContentModelMapper : ContentModelMapperBase
    {
        public CustomContentModelMapper(IContentTypeRepository contentTypeRepository, ReflectionService reflectionService, IContentModelReferenceConverter contentModelService,
            IContentVersionRepository contentVersionRepository, ContentLoaderService contentLoaderService, UrlResolverService urlResolverService,
             ContentApiConfiguration apiConfig, IPropertyConverterResolver propertyConverterResolver
        ) : base(contentTypeRepository, reflectionService, contentModelService, contentVersionRepository, contentLoaderService, urlResolverService, apiConfig, propertyConverterResolver)
        {
        }

        public override int Order => 200; // Any number larger than default which equals to 100.
        public override ContentApiModel TransformContent(IContent content, bool excludePersonalizedContent = false, string expand = "")
        {
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();

            if (ContentReference.StartPage == null ||
                !contentLoader.TryGet(ContentReference.StartPage, out StartPage startPage) ||
                !startPage.EnableContentDeliveryApi)
            {
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Response.StatusCode = 404;
                    HttpContext.Current.Response.End();
                    return new ContentApiModel();
                }
            }

            // Call the base class method when conditions are met
            return base.TransformContent(content, excludePersonalizedContent, expand);
        }

        public override bool CanHandle<T>(T content)
        {
            return content is IContent;
        }

        protected override string ResolveUrl(ContentReference contentLink, string language)
        {
            string resolvedUrl;
            if (this._urlResolver == null)
            {
                resolvedUrl = this._urlResolverService.ResolveUrl(contentLink, language);
            }
            else
            {
                resolvedUrl = this._urlResolver.GetUrl(contentLink, language, new UrlResolverArguments()
                {
                    ContextMode = ContextMode.Default,
                    ForceCanonical = true
                });
            }
            return string.IsNullOrEmpty(resolvedUrl) ? null : UriSupport.AbsoluteUrlBySettings(resolvedUrl);
        }
    }

Optimizely Search & Navigation/Find:
We are currently using version 13.5.8 of Optimizely Search & Navigation/Find to search contents. 

Issue:

1- Since including the Content Search API, the existing Optimizely search functionality has ceased to work. We came across EpiServer Find & EpiServer Content Delivery API conflict  that suggests removing Content Search API package which restores the functionality of the existing Search & Navigation at the expense of removing the Content Search API package.

Is this a known issue, or is there something crucial that I might be overlooking or the custom implementation to inherit ContentModelMapperBase with the above implementation is incorrect? I need to maintain the functionality of the existing search while still utilizing the Content Search API.

2- API calls using queries for Content Search API always returns count 0.

Summary: 

1- Content Delivery APIs works

 https://example.com/api/episerver/v2.0/content/17648   Returns Response

2- Content Search APIs always returns count 0 even when the records exists.

https://example.com/api/episerver/v2.0/search/content?expand=footerContentArea&personalize=true&filter=ContentType%2Fany%28t%3At%20ne%20%27LinkListFooterBlock%27%29%0D%0A&query=insurance Always returns Count 0 even though a record exists for the query passed.

3- After Installing Content Search API package, our existing Optimizely Search & Navigation/Find stopped working .Removing Content Search API package resolves this issue.

4- We need Content Delivery API,Content Search API & existing Optimizely Search & Navigation/Find to work without any package conflicting the other.

Any inputs or insights into resolving this would be greatly appreciated.

Regards.

#314759
Edited, Dec 28, 2023 15:35
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.