【问题标题】:Sitecore 8.2 Lucene search isn't indexing all terms in a computed fieldSitecore 8.2 Lucene 搜索未索引计算字段中的所有术语
【发布时间】:2017-06-08 13:04:41
【问题描述】:

我有一个计算字段,它从项目的子项目中获取信息并将其连接到项目的新字段中。

如果我单步调试调试器,我可以看到计算域正在返回正确的信息。如果我使用 Luke 检查 Sitecore 生成的索引,我还可以看到具有正确值的计算字段。但是,如果我使用 Luke(或在 Sitecore 中)搜索计算字段中的术语,它并不总是返回包含该术语的所有文档。

我认为这可能与具有多种语言版本的项目有关。例如,其中一项具有荷兰语版本和塞尔维亚语(拉丁语)版本。它们的内容中都包含“vooderlen”一词。但是,当我搜索该术语时,只返回塞尔维亚文档。如果我搜索“assiteert”,两个文档都会返回。我不确定为什么有些术语会被忽略。

以下是相关代码:

public class ChildContent : AbstractComputedIndexField
{
    public override object ComputeFieldValue(IIndexable indexable)
    {
        Assert.ArgumentNotNull(indexable, "indexable");
        Item item = indexable as SitecoreIndexableItem;

        if (item == null)
        {
            return null;
        }

        // Only compute child content for Detail Layout templates
        string detailLayoutTemplateId = Settings.GetSetting("DetailLayoutTemplateId");

        if (item.TemplateID.ToString() != detailLayoutTemplateId)
        {
            return null;
        }

        // Get Content Detail item
        string contentDetailId = item["Content Detail"];
        var valueString = new StringBuilder();
        Item contentDetailItem;
        string introContent, mainContent;

        if (string.IsNullOrEmpty(contentDetailId))
        {
            return null;
        }

        contentDetailItem = item.Database.GetItem(ID.Parse(contentDetailId), item.Language);

        if (contentDetailItem == null)
        {
            return null;
        }

        // Concatenate intro and main content
        introContent = contentDetailItem["Intro Content"];
        mainContent = contentDetailItem["Main Content"];

        if (!string.IsNullOrWhiteSpace(introContent))
        {
            valueString.Append(Regex.Replace(introContent, "<.*?>", " ") + " ");
        }

        if (!string.IsNullOrWhiteSpace(mainContent))
        {
            valueString.Append(Regex.Replace(mainContent, "<.*?>", " ") + " ");
        }

        return valueString.ToString();
    }
}

我也在使用下面的搜索配置。

<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
    <fieldNames hint="raw:AddFieldByFieldName">
        <field fieldName="_uniqueid"
            storageType="YES"
            indexType="TOKENIZED"
            vectorType="NO"
            boost="1f"
            type="System.String"
            settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
            <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
        </field>
        <field fieldName="childcontent"
            storageType="YES"
            indexType="TOKENIZED"
            vectorType="NO"
            boost="1f"
            type="System.String"
            settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
        </field>
    </fieldNames>
</fieldMap>

<fields hint="raw:AddComputedIndexField">
    <field fieldName="childcontent">My.Namespace.ComputedFields.ChildContent, MyWebApp</field>
</fields>

【问题讨论】:

    标签: search lucene sitecore multilingual computed-field


    【解决方案1】:

    我注意到,如果我在 Luke 中使用 DutchAnalyzer,我可以获得更多荷兰语的结果。不幸的是,Sitecore 提供的分析器并不多,而且没有一个是特定于语言的,除非您创建自定义分析器。

    幸运的是,这让我走上了正轨,我研究了不同的方法来获取我需要的特定语言的结果。通过将CultureExecutionContext 传递给GetQueryable 方法,我能够得到我期望的结果。

    var queryable = context.GetQueryable<SearchResultItem>(
        new CultureExecutionContext(
            CultureInfo.GetCultureInfo(Sitecore.Context.Language.ToString())
        )
    );
    

    【讨论】:

      猜你喜欢
      • 2015-03-30
      • 2012-05-10
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      相关资源
      最近更新 更多