Sitecore 8 XP ContentSearch:从索引中排除路径
Sitecore 8 XP ContentSearch: Exclude path from Indexing
我在使用通用索引 "sitecore_master_index"、"sitecore_web_index" 的 Sitecore 索引时遇到问题,因为 crawler/indexer 会检查数据库中的所有项目。
我导入了数千种具有大量规格的产品,并且产品库中确实有数十万个项目。
如果我可以从索引中排除路径,它就不必检查一百万个项目以排除模板。
跟进
我实现了一个自定义爬虫,它排除了被索引的路径列表:
<index id="sitecore_web_index" type="Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="core">sitecore_web_index</param>
<param desc="rebuildcore">sitecore_web_index_sec</param>
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
<strategies hint="list:AddStrategy">
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
</strategies>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.Utilities.Crawler.ExcludePathsItemCrawler, Sitecore.ContentSearch.Utilities">
<Database>web</Database>
<Root>/sitecore</Root>
<ExcludeItemsList hint="list">
<ProductRepository>/sitecore/content/Product Repository</ProductRepository>
</ExcludeItemsList>
</crawler>
</locations>
</index>
此外,我激活了 SwitchOnSolrRebuildIndex,因为它是很棒的 ootb 功能,SC 干杯。
using System.Collections.Generic;
using System.Linq;
using Sitecore.ContentSearch;
using Sitecore.Diagnostics;
namespace Sitecore.ContentSearch.Utilities.Crawler
{
public class ExcludePathsItemCrawler : SitecoreItemCrawler
{
private readonly List<string> excludeItemsList = new List<string>();
public List<string> ExcludeItemsList
{
get
{
return excludeItemsList;
}
}
protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation = false)
{
Assert.ArgumentNotNull(indexable, "item");
if (ExcludeItemsList.Any(path => indexable.AbsolutePath.StartsWith(path)))
{
return true;
}
return base.IsExcludedFromIndex(indexable, checkLocation);
}
}
}
当导入大量数据时,您应该尝试暂时禁用数据索引,否则您将 运行 陷入爬虫无法跟上的问题。
这里有一个很好的 post 关于在导入数据时禁用索引 - 它适用于 Lucene,但我相信你可以用 Solr 做同样的事情,
http://intothecore.cassidy.dk/2010/09/disabling-lucene-indexes.html
另一种选择是将您的产品存储在单独的 Sitecore 数据库中,而不是主数据库中。
另一个post来自核心:
http://intothecore.cassidy.dk/2009/05/working-with-multiple-content-databases.html
您可以覆盖要更改的索引使用的 SitecoreItemCrawler
class:
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<Database>master</Database>
<Root>/sitecore</Root>
</crawler>
</locations>
然后您可以添加自己的参数,例如ExcludeTree
甚至 ExcludedBranches
.
的列表
并且在class的实现中只是override方法
public override bool IsExcludedFromIndex(IIndexable indexable)
并检查是否在排除节点下。
我在使用通用索引 "sitecore_master_index"、"sitecore_web_index" 的 Sitecore 索引时遇到问题,因为 crawler/indexer 会检查数据库中的所有项目。
我导入了数千种具有大量规格的产品,并且产品库中确实有数十万个项目。
如果我可以从索引中排除路径,它就不必检查一百万个项目以排除模板。
跟进
我实现了一个自定义爬虫,它排除了被索引的路径列表:
<index id="sitecore_web_index" type="Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="core">sitecore_web_index</param>
<param desc="rebuildcore">sitecore_web_index_sec</param>
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
<configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
<strategies hint="list:AddStrategy">
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
</strategies>
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.Utilities.Crawler.ExcludePathsItemCrawler, Sitecore.ContentSearch.Utilities">
<Database>web</Database>
<Root>/sitecore</Root>
<ExcludeItemsList hint="list">
<ProductRepository>/sitecore/content/Product Repository</ProductRepository>
</ExcludeItemsList>
</crawler>
</locations>
</index>
此外,我激活了 SwitchOnSolrRebuildIndex,因为它是很棒的 ootb 功能,SC 干杯。
using System.Collections.Generic;
using System.Linq;
using Sitecore.ContentSearch;
using Sitecore.Diagnostics;
namespace Sitecore.ContentSearch.Utilities.Crawler
{
public class ExcludePathsItemCrawler : SitecoreItemCrawler
{
private readonly List<string> excludeItemsList = new List<string>();
public List<string> ExcludeItemsList
{
get
{
return excludeItemsList;
}
}
protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation = false)
{
Assert.ArgumentNotNull(indexable, "item");
if (ExcludeItemsList.Any(path => indexable.AbsolutePath.StartsWith(path)))
{
return true;
}
return base.IsExcludedFromIndex(indexable, checkLocation);
}
}
}
当导入大量数据时,您应该尝试暂时禁用数据索引,否则您将 运行 陷入爬虫无法跟上的问题。
这里有一个很好的 post 关于在导入数据时禁用索引 - 它适用于 Lucene,但我相信你可以用 Solr 做同样的事情,
http://intothecore.cassidy.dk/2010/09/disabling-lucene-indexes.html
另一种选择是将您的产品存储在单独的 Sitecore 数据库中,而不是主数据库中。
另一个post来自核心:
http://intothecore.cassidy.dk/2009/05/working-with-multiple-content-databases.html
您可以覆盖要更改的索引使用的 SitecoreItemCrawler
class:
<locations hint="list:AddCrawler">
<crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<Database>master</Database>
<Root>/sitecore</Root>
</crawler>
</locations>
然后您可以添加自己的参数,例如ExcludeTree
甚至 ExcludedBranches
.
并且在class的实现中只是override方法
public override bool IsExcludedFromIndex(IIndexable indexable)
并检查是否在排除节点下。