我在Sitecore 8.1环境中创建了一个自定义Lucene索引,如下所示:
<?xml version="1.0"?>
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="Products_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<configuration ref="contentSearch/indexConfigurations/ProductIndexConfiguration" />
<strategies hint="list:AddStrategy">
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
</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/General/Product Repository</Root>
</crawler>
</locations>
<enableItemLanguageFallback>false</enableItemLanguageFallback>
<enableFieldLanguageFallback>false</enableFieldLanguageFallback>
</index>
</indexes>
</configuration>
<indexConfigurations>
<ProductIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<initializeOnAdd>true</initializeOnAdd>
<analyzer ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/analyzer" />
<documentBuilderType>Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilder, Sitecore.ContentSearch.LuceneProvider</documentBuilderType>
<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="key" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
</fieldNames>
</fieldMap>
<documentOptions type="Sitecore.ContentSearch.LuceneProvider.LuceneDocumentBuilderOptions, Sitecore.ContentSearch.LuceneProvider">
<indexAllFields>true</indexAllFields>
<include hint="list:AddIncludedTemplate">
<Product>{843B9598-318D-4AFA-B8C8-07E3DF5C6738}</Product>
</include>
</documentOptions>
<fieldReaders ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/fieldReaders"/>
<indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexFieldStorageValueFormatter"/>
<indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultLuceneIndexConfiguration/indexDocumentPropertyMapper"/>
</ProductIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
实际上,一个指向根的非常简单的索引包括一个模板并存储一个字段。一切正常。但我需要额外的东西:
我知道这也可以在查询中轻松触发,但我想让我的索引更小,以便它们(重新)构建得更快。
第一个可以通过索引web而不是master来解决,但在这种情况下我实际上也想要未发布的。我非常确定我需要一个自定义抓取工具。
第二个(限制语言)实际上更重要,因为我还需要在其他索引中使用它。简单的答案可能也是使用自定义爬虫,但我希望有一种方法可以在没有自定义代码的情况下配置它。是否可以将自定义索引配置为仅包含一组已定义的语言(一个或多个)而不是全部?
答案 0 :(得分:0)
您可以轻松创建自定义处理器,以便过滤所需内容:
namespace Sitecore.Custom
{
public class CustomInboundIndexFilter : InboundIndexFilterProcessor
{
public override void Process(InboundIndexFilterArgs args)
{
var item = args.IndexableToIndex as SitecoreIndexableItem;
var language = Sitecore.Data.Managers.LanguageManager.GetLanguage("en");
if (item != null && (!item.Item.Versions.IsLatestVersion() || item.Item.Language == language))
{
args.IsExcluded = true;
}
}
}
}
将此处理器添加到配置中:
<pipelines>
<indexing.filterIndex.inbound>
<processor type="Sitecore.Custom.CustomInboundIndexFilter, Sitecore.Custom"></processor>
</indexing.filterIndex.inbound>
</pipelines>
答案 1 :(得分:0)
经过一番研究后,我得出的结论是,为了满足所有要求,自定义爬虫是唯一的解决方案。博客代码:http://ggullentops.blogspot.be/2016/10/custom-sitecore-index-crawler.html
主要原因是我们必须能够为每个索引设置这个 - 这对于过滤方法是不可能的。此外,当我们添加新版本时,必须从索引中删除以前的版本 - 如果没有爬虫,也是不可能的......
有相当多的代码,所以我不会在这里复制它们,但是我们必须覆盖SitecoreItemCrawler的DoAdd和DoUpdate方法,对于语言,我们还必须对Update方法进行少量覆盖。