我在玩 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";
}
}
}