6

我在玩 SDL Tridion 2011 (GA) 的自定义搜索索引处理程序。使用Arjen 提供的非常有用的信息,我得到了一些工作,但是我不确定我的执行是否是最佳选择。

要求是能够通过 url 搜索 CMS 中的页面(例如 www.example.com/news/index.html)。为了做到这一点,我使用ISearchIndexingHandler接口创建了一个类(下面的代码)。我正在索引项目的 ContentText 字段中的 url,但是我不确定这是否通常包含页面的其他内容(我认为页面只有元数据,所以应该没问题)。在自定义字段上使用它的优点是我可以简单地在搜索框中键入 url,而不必使用 <url> IN <fieldname> 或类似的东西。

所以我的问题是,是否有任何理由不将 ContentText 用于 Pages,使用自定义字段有什么优势吗?此外,任何对如何处理 BluePrinting 有好的想法的人都会获得奖励分数(如果我在父出版物中创建页面,我希望本地 url 也可以在子出版物中被索引),以及结构组路径被更改的情况(我想我可以从我的索引处理程序中以某种方式触发子页面项的重新索引)。

编码:

using System;
using Tridion.ContentManager.Search;
using Tridion.ContentManager.Search.Indexing.Handling;
using Tridion.ContentManager.Search.Indexing.Service;
using Tridion.ContentManager.Search.Indexing;
using Tridion.ContentManager.Search.Fields;

namespace ExampleSearchIndexHandler
{
    public class PageUrlHandler : ISearchIndexingHandler
    {
        public void Configure(SearchIndexingHandlerSettings settings)
        {               
        }

        public void ExtractIndexFields(IdentifiableObjectData subjectData, Item item, CoreServiceProxy serviceProxy)
        {
            PageData data = subjectData as PageData;
            if (data != null)
            {
                PublishLocationInfo info = data.LocationInfo as PublishLocationInfo;
                string url = GetUrlPrefix(data) + info.PublishLocationUrl;
                item.ContentText = url;
            }
        }

        private string GetUrlPrefix(PageData page)
        {
            //hardcoded for now, but will be read from publication metadata
            return "www.example.com";
        }
    }
}
4

2 回答 2

5

您可以将 url 存储在 ContextText 属性中。该字段用于索引模板内容数据。

Tridion 不索引子发布的共享项目。

在项目修改(创建、更新、删除、本地化和取消本地化)时触发索引。或者您可以使用重新索引工具重新索引您的项目。但无法索引子发布中的共享项目。

于 2012-08-09T11:19:40.437 回答
3

我认为您不能在搜索查询中包含 URL 前缀作为索引项。因为共享项目没有被索引,你可能会从网站结构层索引页面,它永远不会发布。

移动结构组时,您必须创建一个事件处理程序,该处理程序使用 TOM.NET API 的受保护方法触发重新索引所有子页面。此方法不是公共 API 的一部分,因此发布该解决方案的代码可能会声明我是一个不受欢迎的 R&D 角色 :)

在重新索引任何内容之前,您应该将结构组的原始发布位置 url 存储在TcmEventArgs.ContextVariables属性中,以便您可以验证是否需要重新索引操作。

于 2012-08-10T07:51:57.403 回答