Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is searching arrays using cts different than searching arrays using node api?

I have a question similar to this question: Marklogic (Nodejs API) - Search documents that match 2 (or more) conditions in object array attribute

I have the following document:

{
  "address": [
    { "type": "mailing",
      "street": "1001 Main Street",
      "city": "Springfield",
      "state": "MO"
    },
    { "type": "location",
      "street": "989 First Street",
      "city": "Johnstone",
      "state": "WY"
    }
  ]
}

When I run the following code within query console, it correctly does not return the document:

'use strict';

const queryText = 
  cts.jsonPropertyScopeQuery("address", cts.andQuery([
    cts.jsonPropertyWordQuery("city", "Johnstone"),
    cts.jsonPropertyWordQuery("state", "MO")
  ]));

cts.search(queryText);

When I run this code in Node.js, it does return the document because it appears to combine all of the array nodes when evaluating.

const queryText =
  qb.scope(qb.property("address"), qb.and(
    qb.word("city","Johnstone"),
    qb.word("state","MO")
  ));

const query = qb.where(queryText);

Is there a way I can get cts functionality using the Node API? I would prefer to use the Node API versus using invoke on a server side javascript query.

like image 264
Jeff D. White Avatar asked Jan 01 '26 21:01

Jeff D. White


1 Answers

By default, the SJS searches run filtered, which will remove any false positive results. You can toggle that behavior by adding explicit options to the SJS search:

cts.search(queryText, "unfiltered");

By default, the Node.js queries are run unfiltered, which means that you may encounter false positive results.

In order to get your Node.js search running filtered, add the filtered search option to your query:

const query = qb.where(queryText)
  .withOptions({search:['filtered']});
like image 76
Mads Hansen Avatar answered Jan 04 '26 13:01

Mads Hansen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!