Tee*_*now 2 lucene sitecore sitecore8
我正在尝试允许内容编辑器选择从搜索页面中排除项目.正在搜索的模板上有一个复选框,指示它是否应该显示.我已经看到一些涉及从Sitecore.Search.Crawlers.DatabaseCrawler继承并覆盖AddItem方法的答案(从Sitecore的Lucene搜索索引中有选择地排除项目 - 在使用IndexViewer重建时有效,但在使用Sitecore的内置工具时无效).但是,从控制面板重建索引时似乎没有遇到此问题.我已经能够在Sitecore.ContentSearch.SitecoreItemCrawler中找到一个名为RebuildFromRoot的方法.有没有人确切知道该问题的DatabaseCrawler方法何时被击中?我有一种感觉,我需要使用自定义SitecoreItemCrawler和DatabaseCrawler,但我不是积极的.任何见解将不胜感激.我正在使用Sitecore 8.0(rev.150621).
从Sitecore中的默认Lucene爬网程序实现继承并覆盖该IsExcludedFromIndex方法,返回true以将项目排除在索引之外:
using Sitecore.ContentSearch;
using Sitecore.Data.Items;
namespace MyProject.CMS.Custom.ContentSearch.Crawlers
{
public class CustomItemCrawler : Sitecore.ContentSearch.SitecoreItemCrawler
{
protected override bool IsExcludedFromIndex(SitecoreIndexableItem indexable, bool checkLocation = false)
{
bool isExcluded = base.IsExcludedFromIndex(indexable, checkLocation);
if (isExcluded)
return true;
Item obj = (Item)indexable;
if (obj["Exclude From Index"] != "1") //or whatever logic you need
return true;
return false;
}
protected override bool IndexUpdateNeedDelete(SitecoreIndexableItem indexable)
{
if (base.IndexUpdateNeedDelete(indexable))
{
return true;
}
Item obj = indexable;
return obj["Exclude From Index"] == "1";
}
}
}
Run Code Online (Sandbox Code Playgroud)
IndexUpdateNeedDelete如果在将来某个日期更新项目,则需要该方法从索引中删除项目.
使用补丁文件替换您需要索引的爬网程序.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration>
<indexes>
<index id="sitecore_master_index">
<locations>
<crawler>
<patch:attribute name="type">MyProject.CMS.Custom.ContentSearch.Crawlers.CustomItemCrawler, MyProject.CMS.Custom</patch:attribute>
</crawler>
</locations>
</index>
...
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>
Run Code Online (Sandbox Code Playgroud)
之后您必须重建索引(从控制面板中可以正常),以便排除这些项目.
| 归档时间: |
|
| 查看次数: |
1229 次 |
| 最近记录: |