如何获取Marklogic数据库中的文档总数? [英] How to get total number of documents in Marklogic database?

查看:30
本文介绍了如何获取Marklogic数据库中的文档总数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Marklogic数据库中大约有20个lacs文档.我想在我的搜索应用程序中进行分页的文档总数.为了获得总数,我正在使用

I have around 20 lacs documents in Marklogic Database. I want the total number of documents in my search application for pagination. For getting the totals I am using

xdmp:estimate(cts:search(doc(), $query))

其中$ query是cts:and-query中组合的各种查询的组合.但是我没有得到正确的总数.当$ query为空白时,它显示的计数比数据库中文档的总数高得多.当我使用

where $query is the combination of various queries combined in cts:and-query. But I am not getting the correct total. When $query is blank it shows much higher count than the total number of documents in the database. When I use

xdmp:estimate(doc())

它向我显示了正确的总数,但它将是静态总数,不会根据查询而改变.我希望根据响应特定查询返回的结果总计,这就是为什么我将$ query作为参数传递但未显示正确的总计的原因. fn:count()显示正确的总计,但是当文档数在20 lacs左右时,fn:count()不起作用,因为fn:count()慢于xdmp:estimate().

it shows me the correct total but it would be static total which would not change according to the query. I want the total according to the results returned in response to a particular query that's why I passed $query as an argument but it is not showing correct total. fn:count() shows correct total but when the number of documents are around 20 lacs then fn:count() does not work because fn:count() is slower than xdmp:estimate().

请帮助我获取响应用户输入的搜索词返回的正确文档总数.

Please help me to get the correct total number of documents returned in response to the search term entered by the user.

推荐答案

要了解此处发生的情况,请先阅读http://resources.marklogic.com/library/media/inside-marklogic

To understand what is going on here, start by reading the architecture whitepaper from http://resources.marklogic.com/library/media/inside-marklogic

现在尝试这个测试案例:

Now try this test case:

xdmp:estimate(doc()),
xdmp:estimate(cts:search(doc(), ()))

第一个表达式将计算数据库中个文档的数量.第二个表达式将计算数据库中文档片段的数量.因此,如果结果不同,则可能配置了片段根或片段父对象.一些特殊文档还创建了额外的片段:我认为拼写词典和同义词库文档可以做到这一点.

The first expression will count the number of documents in the database. The second expression will count the number of document fragments in the database. So if the results are different, you probably have fragment roots or fragment parents configured. Some special documents also create extra fragments: I think spelling dictionaries and thesaurus documents do this.

如果要将估算值限制为XML文档根,请在可搜索表达式中指定文档根QName,或者,如果您不在乎根元素名称,则使用/*.

If you want to restrict the estimate to XML document roots, specify the document root QName(s) in the searchable expression, or use /* if you do not care about the root element name.

xdmp:estimate(cts:search(/*, ()))

您还可以使用cts:query参数指定仅出现在您要计数的文档中的QName.

You could also use the cts:query argument to specify a QName that only appears in the documents you want to count.

这篇关于如何获取Marklogic数据库中的文档总数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆