Kentico 13 API SearchHelper.Search returns .net core 中的对象类型与 .net mvc 中的对象类型不同

Kentico 13 API SearchHelper.Search returns different object type in .net core than it does in .net mvc

不确定是否有人遇到过这个问题,但目前正在将 K13 MVC 项目移植到 K13 .Net 核心 (5.0) - 两者都使用相同的 CMS,只是不同的 Kentico 库包,但具有相同的修补程序版本。

标准搜索 API 功能在搜索查询中使用完全相同的参数,但发现 .net 核心实例将 return TreeNode 在其 searchResults.Items 数据对象中MVC 将 return 它的强类型对象

函数

        protected ItemsAndCount<News> GetItemsAndCount(string nodeAliasPath, int pageSize = 12, string searchText = "", int currentPage = 0, int category = 0, int year = 0)
    {
        var culture = LocalizationContext.CurrentCulture.CultureCode;
        var defaultCulture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName);
        var combineWithDefaultCulture = SiteInfoProvider.CombineWithDefaultCulture(SiteContext.CurrentSiteName);
        var documentTypes = News.CLASS_NAME;
        var docCondition = new DocumentSearchCondition(documentTypes, culture, defaultCulture, combineWithDefaultCulture);
        var condition = new SearchCondition(GetExtraConditions(category, year), SearchModeEnum.ExactPhrase, SearchOptionsEnum.NoneSearch, docCondition, false);
        var query = ValidationHelper.GetString(searchText, string.Empty);
        var path = nodeAliasPath + "/";

        var parameters = new SearchParameters
        {
            Path = path,
            SearchFor = SearchSyntaxHelper.CombineSearchCondition(query, condition),
            SearchSort = OrderBy,
            CurrentCulture = LocalizationContext.CurrentCulture.CultureCode,
            DefaultCulture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName),
            CombineWithDefaultCulture = SiteInfoProvider.CombineWithDefaultCulture(SiteContext.CurrentSiteName),
            User = MembershipContext.AuthenticatedUser,
            SearchIndexes = SearchIndexHelper.SEARCHINDEX_NEWS,
            DisplayResults = pageSize,
            StartingPosition = currentPage == 0 ? 0 : (currentPage - 1) * pageSize,
            NumberOfProcessedResults = 10000
        };

        var searchResult = SearchHelper.Search(parameters);
        //TotalNoOfRecords = searchResult.TotalNumberOfResults;

        return new ItemsAndCount<News>
        {
            Items = GetItems(searchResult.Items).ToList(),
            Count = searchResult.TotalNumberOfResults
        };
    }

所以根据API docs for SearchHelper, this does look like intended behavior. But you don't actually have to use SearchHelper. You could call the Azure Search client directly and work with the SearchDocument object it returns. An example of this is in the LearningKit for 13.

由于所有生成的代码文件都在一个单独的库中,所以这变成了一个问题

https://docs.xperience.io/custom-development/adding-custom-assemblies#Addingcustomassemblies-Enablingclassdiscovery

让我感到震惊的是,网站的所有其余部分实际上 运行 没有这个,只有 searchitems 和 customtableitems 没有返回强类型。