I'm trying to work with arrays. This is some working code that explains what I am doing.
// query
var a = ["1000", "2000", "3000"];
var b = ["2000"];
for (i in b) {
var index = a.indexOf(b[i]);
};
if (index > -1) {
a.splice(index, 1);
};
a
Now when I use this same logic for my query results, it does not work anymore.
// query
queryDo = cts.andQuery([
cts.jsonPropertyValueQuery("displayable", "true"),
cts.jsonPropertyValueQuery("section", "dikw Track Events"),
cts.jsonPropertyValueQuery("name", 'dikw_default'),
cts.collectionQuery(["reference/application"])
]);
queryDont = cts.andQuery([
cts.jsonPropertyValueQuery("displayable", "false"),
cts.jsonPropertyValueQuery("section", "dikw Track Events"),
cts.jsonPropertyValueQuery("name", 'Helpdesk'),
cts.collectionQuery(["reference/application"])
]);
var qDo = cts.jsonPropertyWords("code", null, "document", queryDo).toArray();
var qDont = cts.jsonPropertyWords("code", null, "document", queryDont).toArray();
for (i in qDont) {
var index = qDo.indexOf(qDont[i]);
};
if (index > -1) {
qDo.splice(index, 1);
};
qDo
I've verified that the result of both queries is an array. The arrays consist of values just like the example code; 1000, 2000, etc. Also, when I use a notAndQuery to exclude results from the 2nd query from the first, this has no effect.
When I look at qDo[2] for example, the right value is returned.
My andNotQuery:
queryDo = cts.andQuery([
cts.jsonPropertyValueQuery("displayable", "true"),
cts.jsonPropertyValueQuery("section", "dikw Track Events"),
cts.jsonPropertyValueQuery("name", 'dikw_default'),
cts.collectionQuery(["reference/application"])
]);
queryDont = cts.andQuery([
cts.jsonPropertyValueQuery("displayable", "false"),
cts.jsonPropertyValueQuery("section", "dikw Track Events"),
cts.jsonPropertyValueQuery("name", 'Helpdesk'),
cts.collectionQuery(["reference/application"])
]);
andnot = cts.andNotQuery(queryDo, queryDont);
result = cts.jsonPropertyWords("code", null, "document", andnot);
After filing a bug at MarkLogic I got this repsonse from the engineering team:
"The return from the lexicon call is a
StringWithFrequency
(not just a String) so the JS layer wraps it"
You can create an Array from the call to cts.jsonPropertyWords
as you did before, but you'll need to iterate through and get the string values for each item in turn first. Something like this:
cts.jsonPropertyWords
as beforeindexOf
will work on the new Array.Work around
var trackCodes = cts.jsonPropertyWords("code", null, "document", cts.andQuery([])).toArray();
var tc2 = new Array();
for (var i = 0; i < trackCodes.length; i++){
tc2.push(trackCodes[i].toString())
}
tc2.indexOf(["your value"])