首页 > 解决方案 > 搜索结果转换中的多个索引不适用于 Kentico

问题描述

我有两种不同的索引,至少在我的本地索引的搜索预览中都可以正常工作。我将它们都添加到索引区域的智能搜索部分,一个是页面爬虫,第二个是在媒体库中搜索的自定义索引。问题是结果只与爬虫的结果匹配,并且没有显示任何自定义索引。我认为问题在于我的 smartSearchResults 转换,因为每次我尝试从自定义索引中添加一个字段时,我都会收到该值不存在的错误。我的问题是如何使用两个索引来检索同一 Web 部件中的所有结果?

这就是变形的样子

   <div class="result">
        <!-- Search result title -->
            <div>
               <a href='<%# SearchResultUrl() %>'>
                    <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.Base.Web.UI.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
              </a>
            </div>

            <p class="content">
           <%#
            IfCompare(GetSearchValue("UseCustomContent"), true,
              SearchHighlight(LimitLength(HTMLHelper.StripTags(Eval<string>("Content")), 280), "<strong>", "</strong>"),
              SearchHighlight(LimitLength(HTMLHelper.StripTags(GetSearchValue("CustomContent").ToString()), 280), "<strong>", "</strong>")
           )
            %>

          </p><!--  content -->
       <%-- MEDIA LIBRARY CONTENT--%>
      <div>
         <%#GetSearchValue("FileName") %>
      </div>


       <div class="file">
          <i class="<%# GetFileIconClass(Eval<string>("documentExtensions")) %>"></i>
       </div><!--  file -->

            </div>
        </div>

但我没有收到任何结果消息

标签: searchindexingkentico

解决方案


在尝试使用它之前,您必须检查该值是否存在。您可以为此使用 IfEmpty。一个例子:

   <%# IfEmpty(GetSearchValue("Email"),"","<span class='label'>Email</span>")%>  
   <%# IfEmpty(GetSearchValue("Email"),"",GetSearchValue("Email"))%>   

推荐阅读