【问题标题】:Full text search in the Attached documents in Kentico CMS 7在 Kentico CMS 7 的附加文档中进行全文搜索
【发布时间】:2012-12-20 08:50:00
【问题描述】:

有什么方法可以搜索附件并在搜索结果中显示附件?我的搜索结果应该只显示包含搜索文本的附件。现在我可以搜索附件并显示附件包含搜索文本的页面。 说,我有一个主页和附件 myattachment.docx 作为其附件。在站点搜索中搜索背景作为搜索文本时,仅包含在 myattachment.docx 中(不包含在主页中),搜索结果显示主页作为搜索结果。我的意图是返回类似 Home/myattachment.docx 的结果,而不是主页。我的页面可以有任意数量的附件。

提前致谢!

【问题讨论】:

    标签: asp.net sql-server-2008 kentico


    【解决方案1】:

    这方面的信息是一个小草图。有关我使用的文档,请参见下文。

    在 AppCode(或 Old_App_Code)中创建自定义全局事件处理程序,确保它是 CMSModule Loader 的部分类。

    在覆盖的Init() 中添加您的自定义事件处理程序,您想要的是DocumentEvents.GetContent.Execute

    发送者对象应该是当前被索引以供搜索的TreeNode。然后,您可以使用该节点访问相关附件并修改事件 args e.content 以将您的文档文本添加到搜索中。

    [CustomDocumentEvents]
    public partial class CMSModuleLoader
    {
        private class CustomDocumentEventsAttribute : CMSLoaderAttribute
        {
            public override void Init()
            {
                // Assigns custom handlers to the appropriate events
                DocumentEvents.GetContent.Execute += Document_GetContent;
            }
    
            private void Document_GetContent(object sender, DocumentEventArgs e)
            {
                TreeNode node = sender as TreeNode;
                if (node != null)
                {
                    //Note, this is psuedo code, this isnt the way to iterate over TreeNode.Attachments
                    foreach( attachment in node.Attachments ) {
                        e.Content += attachment.content;
                    }
                }
            }
    
        }
    }
    

    更多信息

    请参阅http://devnet.kentico.com/docs/devguide/index.html?event_handlers_overview.htm,了解如何在版本 7 中实现自定义事件。

    在版本 5 中查看自定义搜索 http://devnet.kentico.com/Knowledge-Base/Search/How-to-search-for-documents-using-assigned-categor.aspx

    有关版本 5 自定义搜索示例中提到的版本 7 的更新事件名称,请参阅 http://devnet.kentico.com/Knowledge-Base/API-and-Internals/Custom-Handler-Library-compatibility.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多