首页 > 解决方案 > SearchItemInfo 已过时。DNN 7.1 中已弃用

问题描述

我正在尝试在我们的一个模块上实现 ISearchable。

Visual Studio 指示 SearchItemInfo 在 DNN 7.1 中已过时且已弃用。

我找到了这篇文章,但它确实显示了我必须使用的新替代代码,并且 GitHub 上有很多内部函数。

https://www.dnnsoftware.com/answers/searchdatastorecontroller-is-obsolete-in-71

 public SearchItemInfoCollection 
 GetSearchItems(DotNetNuke.Entities.Modules.ModuleInfo ModInfo)
{
    SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();

    List<TestModuleInfo> colTestModules = GetTestModules(ModInfo.ModuleID);

    foreach (TestModuleInfo objTestModule in colTestModules)
    {
        SearchItemInfo SearchItem = new SearchItemInfo(ModInfo.ModuleTitle, objTestModule.Content, objTestModule.CreatedByUser, objTestModule.CreatedDate, ModInfo.ModuleID, objTestModule.ItemId.ToString(), objTestModule.Content, "ItemId=" + objTestModule.ItemId.ToString());
        SearchItemCollection.Add(SearchItem);
    }

    return SearchItemCollection;

    throw new System.NotImplementedException("The method or operation is not implemented.");
}

我确实尝试编写以下方法并在 GetModifiedSearchDocuments 上附加了一个断点并安排了站点爬虫来爬取该站点,但它从未被命中。此外,通过实现此代码,这是否会显示模块上的复选框,使您能够打开和关闭 ISearchable?

//uncomment the interfaces to add the support.
public class FeatureController : ModuleSearchBase
{

    public CommonDataDefinitions.Products.WebProductDetails ProductDetails { get; set; } = null;


    public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDateUtc)
    {
        var searchDocs = new List<SearchDocument>();
        var products = new List<QuickProduct>
        {
            new QuickProduct("CT4455", "Soundbar", "The soundbar is used for entertainment purposes." ),
            new QuickProduct("BD5333", "Laser Pointer", "For Presentations." )
        };

        foreach (var product in products)
        {
            var searchDoc = new SearchDocument
            {
                IsActive = true,
                CultureCode = moduleInfo.CultureCode,
                Title = product.Title,
                Description = product.Description,
                Body = product.Description,
            };
            searchDocs.Add(searchDoc);
        }
        return searchDocs;
    }

}

public class QuickProduct
{
    public string SKU { get; set; }

    public string Title{ get; set; }

    public string Description { get; set; }

    public QuickProduct(string SKU, string Title, string Description)
    {
        this.SKU = SKU;
        this.Title = Title;
        this.Description = Description;
    }
}

标签: c#dotnetnukednn9

解决方案


要了解这些接口是如何实现的,最简单的方法总是查看其工作的模块的源代码,一个很好的起点是 DNN 中包含的 HtmlText 模块。见这里

我依稀记得在安装过程中模块被标记为可搜索(等),因此您必须创建一个升级包并安装它才能使其生效。

另一种方法(用于开发或测试安装)可能是直接在数据库、表 DesktopModules、列 SupportedFeatures 中执行此操作。值为:

1 = Portable
2 = Searchable
4 = Upgradeable

要组合两个功能,请添加数字,例如。便携和可搜索 = 3,全部 = 7 等。

更新此列后,重新启动应用程序池以使其生效。

注意:我只推荐用于开发或测试环境。在生产环境中,您应该使用包来升级扩展。


推荐阅读