【问题标题】:Marklogic cts:element-child-geospatial-query is slow but does not need index?Marklogic cts:element-child-geospatial-query 很慢但不需要索引?
【发布时间】:2014-05-22 19:28:26
【问题描述】:

大家好,Markloggers,

我遇到了一个奇怪的情况。 到目前为止,我的经验是我需要为 cts: 函数设置一个特定的索引才能表现良好。现在我需要在 de db 中搜索带有地理标记的推文,我使用以下查询。 似乎我不需要 teo 为 cts:element-child-geospatial-query() 运行特定索引,但性能很差......我在这里错过了什么?

查询

xquery version "1.0-ml";
declare namespace j = "http://marklogic.com/xdmp/json/basic";

let $lon := 5.470047
let $lat := 51.819565
let $radius := 5.0

let $point := cts:point($lon, $lat)

let $circle := cts:circle($radius,$point)
(:
let $pattern := "/twitter/*"         
let $pointSource := cts:uri-match($pattern)  
:)

(: give back all tweet ids in the circle :)
let $codes := for $p in cts:search(fn:doc(), cts:element-child-geospatial-query(xs:QName("j:geo"), xs:QName("j:point"), $circle))
    return $p//j:id

return fn:count($codes)

一百万条推文中必须包含以下元素:

<json type="object" xmlns="http://marklogic.com/xdmp/json/basic">
... other stuff ...
<dikwmetadata type="object">
<source type="string">
twitter_nederland
</source>
<timestamp type="string">
2014-03-11T21:19:03.818547
</timestamp>
<data xmlns:j="http://marklogic.com/xdmp/json/basic">
<point_was_tried>
2014-03-11T21:19:03.835457+01:00
</point_was_tried>
<postalcode_was_tried>
2014-03-11T21:19:03.835457+01:00
</postalcode_was_tried>
<geo lastupdate="">
<point>
4.65407742 , 52.28828829
</point>
</geo>
<tags lastupdate=""/>
<postalcodes lastupdate="">
<postal_code>
2135
</postal_code>
</postalcodes>
</data>
</dikwmetadata>
</json>

我们将元素范围索引类型=字符串添加到地理和点元素但没有改进...

现在响应 60 秒...

有什么建议吗?

雨果

【问题讨论】:

  • 您可以尝试使用docs.marklogic.com/xdmp:query-trace 来调试它。您应该能够看到是否使用了地理索引。但是,如果您的搜索匹配 100 万份文档并且您正在计算所有文档,那么 60 秒听起来相当不错。也许引入分页?

标签: search twitter marklogic


【解决方案1】:

地理空间索引与范围索引是分开的。您可以在 Admin > Databases > DB-Name > Geospatial Indexes 中创建它们。

除了不过滤运行查询,如果你只是想统计匹配片段的数量,那么你可以使用xdmp:estimate而不是count

xdmp:estimate(cts:search(...))

【讨论】:

  • 很好发现:我错过了它是一个范围索引而不是地理索引。
【解决方案2】:

您可以考虑不过滤地执行 cts:search。
cts:search(fn:doc(), cts:element-child-geospatial-query(xs:QName("j:geo"), xs:QName("j:point"), $circle),("unfiltered" ))
这将仅通过索引而不是实际验证每个命中。

【讨论】:

    猜你喜欢
    • 2013-11-06
    • 2021-11-25
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    相关资源
    最近更新 更多