MarkLogic搜索API-如何对和searchable-expression相同的元素进行排序



我正在尝试对特定元素进行搜索,以便在我的选项中有一个可搜索的表达式。我还想按这个元素的值排序,所以我在value元素上创建了一个元素范围索引。以下是我的搜索选项,希望能让事情变得清楚:

 <options xmlns="http://marklogic.com/appservices/search">
        <term>
            <term-option>case-insensitive</term-option>
        </term>
        <debug>true</debug>
        <searchable-expression>/summary/name/value</searchable-expression>
        <sort-order type="xs:string" direction="ascending">
          <element ns="" name="value"/>
          <annotation>options for search institutions by name</annotation>
        </sort-order>
</options>

问题是,当它进行排序时,它会添加另一个值节点(取自搜索:report id="search-FLWOR")

...order by xs:string(($result//value)[1]) ascending return $result)[1 to 50]

代替:

...order by xs:string(($result)[1]) ascending return $result)[1 to 50]

我该如何防止它这样做?我无法更改可搜索表达式,因为"name"元素有另一个子元素,我不希望在其中搜索。我也不能将排序顺序元素名称留空或设置为当前节点。这似乎很简单,但我还没有找到任何东西来实现这一点。

我们将不胜感激。

您可以使用<name>作为可搜索表达式的目标元素,但随后通过添加<additional-query>:将查询限制为仅查看<value>内部

<options xmlns="http://marklogic.com/appservices/search">
        <term>
            <term-option>case-insensitive</term-option>
        </term>
        <debug>true</debug>
        <searchable-expression>/summary/name</searchable-expression>
        <additional-query>
          <cts:element-query xmlns:cts="http://marklogic.com/cts">
            <cts:element>value</cts:element>
            <cts:and-query/>
          </cts:element-query>
        </additional-query>
        <sort-order type="xs:string" direction="ascending">
          <element ns="" name="value"/>
          <annotation>options for search institutions by name</annotation>
        </sort-order>
</options>

最新更新