cts:word-query to search in a json property for a number

542 Views Asked by At

I have a json file, which has properties which have string values and some have integer values.. I have a generic query which queries a given json property for a value using cts:word-query. This works when the json property has string values, but for number values it does not work.. for eg:

Following is my json string

{
    "id": "35A7D24661CFB8A7E050480A751E4949",
    "moniker": "CL-1460933",
    "entityType": "Cell Line",
    "entitySubType": "Immortalized",
    "bioSafetyLevel": "BL2",
    "name": "WSU-NHL",
    "growthFS": {
        "id": "35A7D24661D1B8A7E050480A751E4949",
        "mediumUsed": "IMDM + 10% HS",
        "percentCO2": 5,
        "percentHumudity": 95,
        "percentSerum": 10,
        "spinnerPlateSpeed": -1,
        "temp": -1,
        "growthConditions": "Suspension"
    },
}

When I do the following

cts:search(fn:doc(),
cts:json-property-scope-query("growthFS", cts:json-property-scope-query("percentHumudity", 
cts:word-query("95", ("wildcarded"), 1))))[1]

I do not get the json, but when I do the following

cts:search(fn:doc(),
cts:json-property-scope-query("growthFS", cts:json-property-value-query("percentHumudity", 95, "wildcarded")))[1]

I get the documents, I was under the impression that cts:word-query works for any xs:atomicType.. If this is not the case, how can I write a generic cts:query without taking into consideration the atomictype of the string (string or number).

1

There are 1 best solutions below

0
On BEST ANSWER

In XML everything is character data, and - without XML Schema - of non-distinguishable type. Because of that, MarkLogic includes all XML values in the so-called universal index as string values, as it has no schema knowledge at index time. In JSON boolean, and number values have explicit type, even without schema, and can therefor be indexed as such. MarkLogic does accordingly.

As a consequence, you need to use value-queries to match JSON numbers. You should be able to do an OR-query on word and value query for the same value:

cts:search(
  fn:collection(),
  cts:json-property-scope-query("growthFS",
    cts:or-query((
      cts:json-property-word-query("percentHumudity", "95", "wildcarded"),
      cts:json-property-value-query("percentHumudity", 95, "wildcarded")
    ))
  )
)[1]

HTH!