本文介绍了Marklogic REST API搜索最新文档版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要使用Marklogic的REST api将MarkLogic搜索限制为最新版本的托管文档.我们正在使用MarkLogic 6.

We need to restrict a MarkLogic search to the latest version of managed documents, using Marklogic's REST api. We're using MarkLogic 6.

使用直接xquery,可以将dls:documents-query()用作附加查询选项(请参见有什么方法可以将marklogic搜索限制在文档的特定版本上.).

Using straight xquery, you can use dls:documents-query() as an additional-query option (seeIs there any way to restrict marklogic search on specific version of the document).

但是REST api需要XML,而不是任意的xquery.您可以轻松地将普通cts查询转换为XML(在QConsole中执行<some-element>{cts:word-query("hello world")}</some-element>).

But the REST api requires XML, not arbitrary xquery. You can turn ordinary cts queries into XML easily enough (execute <some-element>{cts:word-query("hello world")}</some-element> in QConsole).

如果用dls:documents-query()尝试,我会得到:

If I try that with dls:documents-query() I get this:

<cts:properties-query xmlns:cts="http://marklogic.com/cts">
    <cts:registered-query>
        <cts:id>17524193535823153377</cts:id>
    </cts:registered-query>
</cts:properties-query>

除了不完全透明之外...这个数字有多安全?我们需要将其放入查询选项中,因此它并不是每次需要时都可以重新生成的东西.我在这里查看了两个不同的安装,并且安装的数量是相同的,但是否可以保证相同,并且它会改变吗?例如在进行MarkLogic升级?

Apart from being less than totally transparent... how safe is that number? We'll need to put it in our query options, so it's not something we can regenerate every time we need it. I've looked on two different installations here and the the number's the same, but is it guaranteed to be the same, and will it ever change? On, for example, a MarkLogic upgrade?

此外,假设该数字是安全的,那么注册查询将始终存在吗?该文档说,注册的查询可能会在不同时间被系统清除,但这是在讨论用户定义的注册查询,我不确定其中有多少适用于内部查询.

Also, assuming the number is safe, will the registered-query always be there? The documentation says that registered queries may be cleared by the system at various times, but it's talking about user-defined registered queries, and I'm not sure how much of that applies to internal queries.

这是正确的方法吗?如果我们无法做到这一点,我们总是可以设置集合并以此方式限制搜索,但如果可能的话,我们宁愿使用dls:documents-query.

Is this even the right approach? If we can't do this we can always set up collections and restrict the search that way, but we'd rather use dls:documents-query if possible.

推荐答案

dls:documents-query()的调用可确保查询已实际注册(如有需要,可即时进行注册),但不能在REST api中使用.您可以按照Mike的建议使用自定义扩展名来扩展REST api,但也可以使用以下代码:

The call to dls:documents-query() makes sure the query is actually registered (on the fly if necessary), but that won't work from REST api. You could extend the REST api with a custom extension as suggested by Mike, but you could also use the following:

cts:properties-query(
  cts:and-not-query(
    cts:element-value-query(
      xs:QName("dls:latest"),
      "true",
      (),
      0
    ),
    cts:element-query(
      xs:QName("dls:version-id"),
      cts:and-query(())
    )
  )
)

这是dls:documents-query()注册的查询.可能不是将来的证明,因此请在每次升级时进行检查.您可以在/Modules/MarkLogic/dls.xqy

That is the query that is registered by dls:documents-query(). Might not be future proof though, so check at each upgrade. You can find the definition of the function in /Modules/MarkLogic/dls.xqy

HTH!

这篇关于Marklogic REST API搜索最新文档版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 10:30
查看更多