索引附加到某个页面的内容

问题描述 投票:0回答:1

我有这个要求只索引那些数据,用于搜索,这是在某些页面中使用的。例如,如果我上传文档,则在我在某个页面中使用它之前,它不应该可用于搜索。我在网上找到了这个代码

        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;
        });

这在我附加软链接时有效。但是,让我们说一个页面有一个名为Content type的属性,当我在那里添加一些内容时,让我们说一个具有该文档的软链接的块,它不起作用。我被困在那里。任何提示?

c# episerver
1个回答
0
投票

您是否在任何网站上配置了通配符*主机?

检查管理员>管理网站并浏览所有网站以查看是否配置了*。 enter image description here

使用通配符告诉Episerver Find使用包含通配符的站点主URL索引独立内容(即globalassets),而不管它是否被引用。如果您没有配置通配符,Episerver Find无法索引未引用的内容(即globalassets),因为它无法为其生成公共URL。引用的全局资产将使用引用它的站点的域进行索引。希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.