Xquery 在Marklogic中为typeahead应用建议源约束

Xquery 在Marklogic中为typeahead应用建议源约束,xquery,autosuggest,marklogic,Xquery,Autosuggest,Marklogic,比如说,我有5个文档属于不同的集合,例如: Biography, Fiction, Humour, Adventure 例如,文档1位于Adventure集合中: <Book> <title>Harry Potter and the Deathly Hallows</title> <Author>J.K.Rowling</Author> <year>2007</year> </Book> <

比如说,我有5个文档属于不同的集合,例如:

Biography, Fiction, Humour, Adventure 
例如,文档1位于Adventure集合中:

<Book>
<title>Harry Potter and the Deathly Hallows</title>
<Author>J.K.Rowling</Author>
<year>2007</year>
</Book>
<Book>
<title>Steve Jobs</title>
<Author>Walter Issacson</Author>
<year>2011</year>
</Book>
在运行这个查询时,我得到了2011年和2007年的建议,这不是我所期望的。 预期的建议是2011年(因为只需搜索
传记
收藏)。
我已经参考了搜索:建议,但我无法找出到底是什么错误。
我哪里做错了?

Shrey:

建议源中的值将替换引用约束中的值。换言之,这些选项表示,由组约束限定的输入应该来自年份范围索引,这就是您所看到的。有关更多详细信息,请参阅:

http://docs.marklogic.com/guide/search-dev/search-api#id_40748
http://docs.marklogic.com/guide/search-dev/search-api#id_91911
要过滤一组建议,可以使用两个字符串查询调用search:suggest()。第一部分为建议提供输入。第二个提供过滤约束。在上述情况下,筛选约束将是传记集合。有关更多详细信息,请参阅:

http://docs.marklogic.com/guide/search-dev/search-api#id_40748
http://docs.marklogic.com/guide/search-dev/search-api#id_91911

希望这能有所帮助,但是,我可以使用以下选项中的
附加查询
,获得所需的输出:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy"; 
let $options := 
    <options xmlns="http://marklogic.com/appservices/search">
        <additional-query>{cts:collection-query("Biography")}
        </additional-query>
        <constraint name="Search_Element">
          <range collation="http://marklogic.com/collation/" 
           type="xs:string" >
            <element name="year"/>
          </range>
        </constraint> 
        <suggestion-source ref="Search_Element">
          <range collation="http://marklogic.com/collation/" 
          type="xs:string" >
          <element name="year"/>
          </range>
        </suggestion-source>
    </options>
return    
search:suggest("Search_Element:20", $options)
xquery版本“1.0-ml”;
导入模块命名空间搜索=”http://marklogic.com/appservices/search"
位于“/MarkLogic/appservices/search/search.xqy”;
let$options:=
{cts:集合查询(“传记”)}
返回
搜索:建议(“搜索元素:20”,$options)

尽管如此,我还是想知道,如果不使用额外的查询参数,怎么能做到这一点,因为在上面使用集合约束会更优化。

传记是文档所属的集合名称。将另一个查询添加为search:suggest((“组:20”,“传记”),$options)将返回一个空序列。我的问题是,我想从特定范围元素的特定集合中获取有关文档的建议。这里是传记集,年份是元素。我浏览了链接,但无法正确理解,你能详细说明一下这个xquery吗