【问题标题】:Retrieving the field names from sitecore item从 sitecore 项目中检索字段名称
【发布时间】:2016-12-27 13:40:33
【问题描述】:

当我使用 sitecore.seach 在 sitecore 中搜索关键字时,它会返回搜索关键字的项目名称(它所在的位置)。是否有任何选项可以获取项目中的字段名称?

我使用以下代码:

using (IndexSearchContext context = searchIndex.CreateSearchContext())
{
   SearchHits hits = context.Search(searchString, new SearchContext(SiteRoot));
   var results = hits.FetchResults(0, 100);

   foreach (SearchResult result in results)
   {
      try
      {
         Item item = result.GetObject<Item>();
         if (item != null)
         {
            results.AddResultToCategory(result, categoryName);
         }
      }
      ...
   }
}

【问题讨论】:

    标签: sitecore


    【解决方案1】:

    如果我正确理解您的目标,您想找出找到搜索字符串的确切字段(字段名称),对吧?

    如果是这种情况,那么您应该获取项目字段的集合 (item.Fields),并遍历它以检查字段值中的搜索字符串。

    据我所知,Sitecore Search shell 应用程序在显示结果时的工作方式相同:项目取自 SearchResult,而字段集合只是使用简单的 text.IndexOf() 比较来迭代查找命中。

    而且我不知道有什么不同的方法可以实现这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2017-02-28
      相关资源
      最近更新 更多