我正在尝试在我们的一个模块上实现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上附加了一个断点,并安排了Site Crawler来抓取该站点,但它从未被命中。此外,通过实现此代码,这将显示模块上的复选框,使您可以打开和关闭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;
}
}
了解如何实现这些接口的最简单方法是查看其工作模块的源代码,一个非常好的起点是DNN中包含的HtmlText模块。见here。
我依稀记得在安装过程中将模块标记为可搜索(等),因此您必须创建升级包并安装它才能使其生效。
另一种方法(用于开发或测试安装)可以直接在数据库表DesktopModules,SupportedFeatures列中执行此操作。价值观是:
1 = Portable
2 = Searchable
4 = Upgradeable
要组合两个功能,请添加数字,例如。便携式和可搜索= 3,全部= 7等
更新此列后,重新启动应用程序池以使其生效。
注意:我仅建议用于开发或测试环境。在生产环境中,您应该使用包来升级扩展。