Marklogic在数组或对象内搜索并仅返回匹配的数组项(javascript) [英] Marklogic search inside array or objects and return only matching array items (javascript)

查看:113
本文介绍了Marklogic在数组或对象内搜索并仅返回匹配的数组项(javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在文档中进行搜索,但只能使用数组元素内部的特定属性进行搜索?此外,结果可能仅包含匹配的数组元素,而不包含整个文档(因为同一文档中的其他数组元素可能不匹配).

Is it possible to search across documents but only search using specific properties inside the array elements? Furthermore is it possible for the results to only contain the matching array elements and not the whole document (as other array elements in the same document may not match).

示例:给出了JSON Marklogic文档 { "name": "aName", "children": [{ "name": "A", "target": { "min": 2, "max": 10 } },{ "name": "B", "target": { "min": 22, "max": 32 } },{ "name": "C", "target": { "min": 4, "max": 7 } }] } 我只想匹配children,其中target.min< 5和target.max> 5.

Example: given a JSON Marklogic document { "name": "aName", "children": [{ "name": "A", "target": { "min": 2, "max": 10 } },{ "name": "B", "target": { "min": 22, "max": 32 } },{ "name": "C", "target": { "min": 4, "max": 7 } }] } I only want to match children where target.min < 5 and target.max > 5.

在这种情况下,只有children[0]children[2]将匹配.然后,我如何指定查询以仅返回: [ { "name": "A", "target": { "min": 2, "max": 10 } }, { "name": "C", "target": { "min": 4, "max": 7 } } ]

In this case only children[0] and children[2] will match. How do I then specify a query to return only: [ { "name": "A", "target": { "min": 2, "max": 10 } }, { "name": "C", "target": { "min": 4, "max": 7 } } ]

如何构造相关查询. N.B.我更喜欢服务器端的javascript或Node.js实现.

How do I construct the relevant query. N.B. I'd prefer server side javascript or Node.js implementation.

推荐答案

对于Node.js,请看一下queryBuilder.extract或搜索响应转换,以查看这两个转换是否满足您的需求.此处讨论了这两个主题: http://docs.marklogic.com/guide /node-dev/search#id_24160 .

For Node.js, take a look at queryBuilder.extract or search response transformations to see if either of those meet your needs. Both topics are discussed under here: http://docs.marklogic.com/guide/node-dev/search#id_24160.

在SJS中,jsearch映射器和reducer挂钩提供了类似的功能.请参阅使用Map and Reduce转换结果"中的以下主题: http://docs.marklogic.com/guide/search-dev/javascript#id_49222 .

In SJS, the jsearch mapper and reducer hook provides similar capabilities. See the following topic on "Transforming Results with Map and Reduce": http://docs.marklogic.com/guide/search-dev/javascript#id_49222.

这篇关于Marklogic在数组或对象内搜索并仅返回匹配的数组项(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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