Skip to content Skip to sidebar Skip to footer

Marklogic Search Inside Array Or Objects And Return Only Matching Array Items (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 matchi

Solution 1:

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.

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.

Solution 2:

In MarkLogic 9, you could use TDE to project a row for each child with the min and max values and use an Optic query with the comparisons.

Right now, Optic isn't available for Node.js, but that's planned.

In MarkLogic 8, the best approach would be to model each child as a separate document and create a range index on the min and max.

Hoping that helps,

Solution 3:

try this

var a = {
    "name": "aName",
    "children": [{
        "name": "A",
        "target": {
            "min": 2,
            "max": 10
        }
    },{
        "name": "B",
        "target": {
            "min": 22,
            "max": 32
        }
    },{
        "name": "C",
        "target": {
            "min": 4,
            "max": 7
        }
    }]
};

var b = [];

for(var i of a.children){
if(i.target.min < 5 && i.target.max > 5){
 b.push(i);
}

}

console.log(b);

Post a Comment for "Marklogic Search Inside Array Or Objects And Return Only Matching Array Items (javascript)"