【问题标题】:Ektron solr search with smartform fields facing aproblemEktron solr 搜索智能表单字段面临问题
【发布时间】:2013-08-06 07:08:41
【问题描述】:

我正在使用 ektron 9。

我创建了一个智能表单,并使用搜索 API 实现了对智能表单字段的搜索。 为此,我正在使用 Ektron.Cms.Framework.Search.SearchManager 类。它适用于单个 Xpath 值。

当我的智能表单有多个具有相同 Xpath 的字段时,搜索 api 只返回第一次出现的结果。

在下面的示例中,当我使用 Xpath "/root/Books/Book/Title" 搜索 Book->Title 时,结果总是返回 "Hai"。

<root>
<Books>
<Book>
<Id>1
</Id>
<Title>Hai
</Title>
<Book>
<Book>
<Id>2
</Id>
<Title>Hello
</Title>
<Book>
</Books>
</root>

我怎样才能在结果中也得到“你好”?有没有单独的api来处理这个? 或者是否可以以单独的方式处理这种情况,例如通过指定这样的“/root/Books/Book[id=1]/Title”?

有关搜索的更多详细信息,请查看: http://documentation.ektron.com/cms400/v85/webhelp/Navigating/Search85/APISearch.htm#Major

【问题讨论】:

    标签: ektron


    【解决方案1】:

    你没有提供你正在使用的代码,所以很难看出你哪里出错了。

    但是,这里有一些代码允许您使用 Solr(或 Microsoft Search Server)在 Ektron 中搜索 SmartForm 字段。

    这会在名为“Path”的字段中搜索特定 SmartForm - 使用 XPath“/root/Path”进行访问。

    Ektron.Cms.Framework.Search.SearchManager sManager = new Ektron.Cms.Framework.Search.SearchManager();
    AdvancedSearchCriteria searchCriteria = new AdvancedSearchCriteria();
    
    searchCriteria.ExpressionTree = SearchContentProperty.XmlConfigId.EqualTo(YourSmartFormID);
    
    searchCriteria.ExpressionTree &= SearchSmartFormProperty.GetStringProperty("/root/Path").EqualTo(YourPathValue);
    
    searchCriteria.PagingInfo = new PagingInfo(10, 1);
    
    searchCriteria.ReturnProperties = new HashSet<PropertyExpression>
    { 
        SearchContentProperty.Id, 
        SearchContentProperty.Title, 
        SearchContentProperty.QuickLink 
    };
    
    SearchResponseData response = sManager.Search(criteria);
    

    以上示例要求 Search(Solr 或 Search Server)返回三个属性:Id、Title 和 QuickLink。

    如果您还没有,您可能需要为 Ektron.Cms.Search 和 Ektron.Cms.Framework.Search 添加“使用”语句。

    Ektron API 的最佳参考指南是 this site

    【讨论】:

      【解决方案2】:

      到目前为止,Ektron 9 的 solr 集成对我来说相当有问题(当然,它甚至还没有真正推出!),所以这实际上可能只是一个错误。

      也就是说,当您选择/root/Books/Book 时是否会发生同样的事情,还是只返回一个结果?

      如果 API 只返回一个结果,您可以尝试多次搜索,直到结果为空。一般的伪代码算法是:

      var i = 0;
      List<item> allItems = new List<item>();
      item myItem = select("(/root/Books/Book/Title)[0]");
      while(myItem != null){
        allItems.add(myItem);
        i++;
        myItem = select("(/root/Books/Book/Title)["+i+"]");
      }
      

      请记住,这是非常低效的。

      【讨论】:

        【解决方案3】:

        Solr 支持多值属性,因此在索引 smartform 字段时,它们会被索引为真正的多值字段,而不是像 Search Server 2010/FAST 2010 那样的分隔符分隔值。

        如果是多值字段,您必须使用 SearchResponseData 中以下列方式返回的 SearchResultData

        对于多值字符串属性的情况 GetValue(StringMultiValuePropertyExpression) 或使用索引器 [StringMultiValuePropertyExpression]

        对于多值浮点属性的情况 GetValue(DecimalMultiValuePropertyExpression) 或使用索引器 [DecimalMultiValuePropertyExpression]

        参考 http://reference.ektron.com/developer/framework/Search/SearchResultData/

        如果不使用 MultiValuePropertyExpression,API 将返回您所看到的值集的第一个值。

        希望这会有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-09
          • 1970-01-01
          • 2013-06-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多