我有这个要求,只索引该数据以进行搜索,该数据正在某些页面中使用。例如,如果我上载文档,则除非在某些页面上使用它,否则该文件不可搜索。我在网上找到了这段代码
ContentIndexer.Instance.Conventions.ForInstancesOf().ShouldIndex(x =>
{
var contentRepository =
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();
var contentSoftLinkRepository =
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();
var softLinks = contentSoftLinkRepository.Load(x.ContentLink, true);
try
{
foreach (var softLink in softLinks)
{
if (softLink.SoftLinkType == ReferenceType.ExternalReference ||
softLink.SoftLinkType == ReferenceType.ImageReference)
{
var content =
contentRepository.Get(softLink.OwnerContentLink);
if (!ContentIndexer.Instance.Conventions.ShouldIndexConvention.ShouldIndex(content).Value) // don't index referenced file if content is marked as not indexed
{
continue;
}
// only index if content is published
var publicationStatus =
content.PublishedInLanguage()[softLink.OwnerLanguage.Name];
if (publicationStatus != null &&
(publicationStatus.StartPublish == null ||
publicationStatus.StartPublish < DateTime.Now) &&
(publicationStatus.StopPublish == null ||
DateTime.Now < publicationStatus.StopPublish))
{
return true;
}
}
}
}
catch
{
// ooops something went wrong. Better not index this one ;-)
}
return false;
});
当我附加软链接时,此方法有效。但是,可以说一个页面具有一个称为“内容类型”的属性,当我在其中添加内容时,可以说一个具有到该文档的软链接的块不起作用。我被困在那里。有提示吗?