Sitecore Lucene索引 - 在父Lucene doc中保存子字段值

时间:2010-01-04 00:14:35

标签: indexing lucene lucene.net sitecore

我有一个Sitecore内容结构,其中任何单个项目都可以有许多子项目,用于存储列表的可枚举内容(显然是一种相当标准的方法)。我希望索引这些项目,但将其索引数据存储在Lucene中的父文档中。这应该有望加快搜索位,通过节省时间排序多个结果,这些结果都有效地指向相同的URL。下面是我将实现的自定义索引器的一些基本代码。

如果这是(a)可能和(b)一个好主意,谁能让我知道?我看到的主要问题是Lucene doc已经看起来已经创建了 - 我是否需要删除它?此外,如果父项的Lucene doc不存在,我是否需要创建它?当父项被编入索引时,它是否会被覆盖/丢失。在那里看起来有点冲突的空间。

另一个选择是我不索引子项,但在索引父项时获取它们的值。现在我想起来了,这似乎是更好的方式去......意见?

public class CustomIndex : Sitecore.Data.Indexing.Index
{
    public CustomIndex(string indexName): base(indexName) {}

    protected override void AddFields(Item item, Document document)
    {
        //is item a sub-item (promo item)
        if (...)
        {
            //delete the sub-item lucene doc
            DeleteDoc(document); //is this possible or needed?

            //get parent item
            Item parentItem = item.Parent;

            //get lucene document for parent item
            Document parentDoc = GetParentDoc();

            //add fields to parent item lucene document
            parentDoc.Add(...);
            parentDoc.Add(...);
        }
        else
        {
            base.AddFields(item, document);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

是的我同意,选项#2更好 - 当你在父母那里时给孩子们做索引。主要是因为你不能保证遍历将发生在什么顺序,所以文件可能会像你说的那样重新创建。