【问题标题】:Sitecore ContentSearch duplicate indexes when saving items保存项目时 Sitecore ContentSearch 重复索引
【发布时间】:2016-12-22 18:44:02
【问题描述】:

我已经为我们的应用程序实现了一个索引,该索引应该从主数据库上的项目桶中索引我们的项目,但似乎每次更新和保存项目时(未发布,因为索引在主数据库上工作)为该项目创建了一个附加索引,这意味着该项目的另一个搜索结果。
重新生成索引后似乎没有问题,桶中的每个项目都被索引一次。 我正在为下面的搜索功能添加索引配置:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
    <customSearchNewsItem>
        <Configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
            <IndexAllFields>true</IndexAllFields>
            <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
                <!-- Add fields to the Default Index Configuration -->
                <fieldNames hint="raw:AddFieldByFieldName">
                    <fieldType fieldName="_rendering" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="Sitecore.SharedSource.Search.DynamicFields.RenderingField,Sitecore.SharedSource.Search"
                        settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
        <field fieldName="category" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String"   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                </fieldNames>
            </fieldMap>
            <indexFieldStorageValueFormatter type="Sitecore.ContentSearch.LuceneProvider.Converters.LuceneIndexFieldStorageValueFormatter, Sitecore.ContentSearch.LuceneProvider">
                <converters hint="raw:AddConverter">
                    <converter handlesType="System.Guid"                                                          typeConverter="Sitecore.ContentSearch.Converters.IndexFieldGuidValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.Data.ID, Sitecore.Kernel"                                    typeConverter="Sitecore.ContentSearch.Converters.IndexFieldIDValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.Data.ShortID, Sitecore.Kernel"                               typeConverter="Sitecore.ContentSearch.Converters.IndexFieldShortIDValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="System.Boolean"                                                       typeConverter="Sitecore.ContentSearch.LuceneProvider.Converters.IndexFieldBooleanValueConverter, Sitecore.ContentSearch.LuceneProvider" />
                    <converter handlesType="System.DateTime"                                                      typeConverter="Sitecore.ContentSearch.LuceneProvider.Converters.IndexFieldDateTimeValueConverter, Sitecore.ContentSearch.LuceneProvider" />
                    <converter handlesType="System.DateTimeOffset"                                                typeConverter="Sitecore.ContentSearch.Converters.IndexFieldDateTimeOffsetValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="System.TimeSpan"                                                      typeConverter="Sitecore.ContentSearch.Converters.IndexFieldTimeSpanValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.ContentSearch.SitecoreItemId, Sitecore.ContentSearch"        typeConverter="Sitecore.ContentSearch.Converters.IndexFieldSitecoreItemIDValueConvertor, Sitecore.ContentSearch">
                        <param type="Sitecore.ContentSearch.Converters.IndexFieldIDValueConverter, Sitecore.ContentSearch"/>
                    </converter>
                    <converter handlesType="Sitecore.ContentSearch.SitecoreItemUniqueId, Sitecore.ContentSearch"  typeConverter="Sitecore.ContentSearch.Converters.IndexFieldSitecoreItemUniqueIDValueConverter, Sitecore.ContentSearch">
                        <param type="Sitecore.ContentSearch.Converters.IndexFieldItemUriValueConverter, Sitecore.ContentSearch"/>
                    </converter>
                    <converter handlesType="Sitecore.Data.ItemUri, Sitecore.Kernel"                               typeConverter="Sitecore.ContentSearch.Converters.IndexFieldItemUriValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.Globalization.Language, Sitecore.Kernel"                     typeConverter="Sitecore.ContentSearch.Converters.IndexFieldLanguageValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="System.Globalization.CultureInfo"                                     typeConverter="Sitecore.ContentSearch.Converters.IndexFieldCultureInfoValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.Data.Version, Sitecore.Kernel"                               typeConverter="Sitecore.ContentSearch.Converters.IndexFieldVersionValueConverter, Sitecore.ContentSearch" />
                    <converter handlesType="Sitecore.Data.Database, Sitecore.Kernel"                              typeConverter="Sitecore.ContentSearch.Converters.IndexFieldDatabaseValueConverter, Sitecore.ContentSearch" />
                </converters>
            </indexFieldStorageValueFormatter>
            <IndexDocumentPropertyMapper type="Sitecore.ContentSearch.LuceneProvider.DefaultLuceneDocumentTypeMapper, Sitecore.ContentSearch.LuceneProvider" />
            <include hint="list:ExcludeTemplate">
                <template>{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}</template>
            </include>
        </Configuration>
    </customSearchNewsItem>
    <contentSearch>
        <configuration type="Sitecore.ContentSearch.LuceneProvider.LuceneSearchConfiguration, Sitecore.ContentSearch.LuceneProvider">
            <indexes hint="list:AddIndex">
                <index id="sitecore_cope_news_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
                    <param desc="name">$(id)</param>
                    <param desc="folder">$(id)</param>
                    <!-- This initializes index property store. Id has to be set to the index id -->
                    <param desc="propertyStore" ref="contentSearch/databasePropertyStore" param1="$(id)" />
                    <Configuration ref="customSearchNewsItem/Configuration" />
                    <strategies hint="list:AddStrategy">
                        <!-- NOTE: order of these is controls the execution order -->
                        <strategy ref="contentSearch/indexUpdateStrategies/syncMaster" />
                    </strategies>
                    <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
                        <policies hint="list:AddCommitPolicy">
                            <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
                        </policies>
                    </commitPolicyExecutor>
                    <locations hint="list:AddCrawler">
                        <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                            <Database>master</Database>
                            <Root>/sitecore/content/Cope/COPE/Site Settings/Site Content/News</Root>
                        </crawler>
                    </locations>
                </index>
            </indexes>
        </configuration>
    </contentSearch>
</sitecore>

【问题讨论】:

  • 嗨,我不明白你的配置文件的结构,[sitecore -> customSearchNewsItem -> Configuration] 应该是 [sitecore -> Configuration -> defaultIndexConfiguration]

标签: sitecore lucene sitecore7


【解决方案1】:

Lucene 通过其唯一 ID 识别索引,即 &lt;fieldNames&gt; 部分中的 _uniqueid 字段

由于您正在创建自己的/单独的索引配置,因此您需要在 fieldNames 部分中添加该字段部分,以便它能够识别索引。

应该是这样的

<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>
    <!-- Your custom Fields -->
</fieldNames>

【讨论】:

    【解决方案2】:

    问题在于您覆盖了默认的 fieldNames 配置。您必须在 fieldMap/fieldNames 部分中包含更多字段,因为 Sitecore 需要将多个字段转换为小写才能在 lucene 中正确匹配文档。

    不要只添加您的自定义字段 _renderingcategory,而是从 DefaultIndexConfiguration 复制整个部分,然后添加您的自定义字段。

    <fieldNames hint="raw:AddFieldByFieldName">
        <fieldType fieldName="_rendering" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="Sitecore.SharedSource.Search.DynamicFields.RenderingField,Sitecore.SharedSource.Search" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
    
        <field fieldName="category" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String"   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
    
        <!-- Fields from DefaultIndexConfiguration here -->         
    
    </fieldNames>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-02
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多