cts.parse( query as String, [bindings as Object?] ) as cts.query
Parses a query string
Parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query | The query string. For details, see Creating a Query From Search Text With cts:parse in the Search Developer's Guide. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bindings |
Bindings for mapping x:y parts of the query string.
The map key can be either a simple string with no embedded spaces or
punctuation or the empty string. The empty string defines the parsing
of untagged words. For details, see
Binding a Tag to a Reference, Field, or Query Generator in the Search Developer's Guide.
The map value for the label can be:
|
cts.search(cts.parse('cat AND dog')) ==> all documents containing the words "dog" and "cat"
cts.parse('cat NEAR/5 dog AND mouse') ==> cts.andQuery( [cts.nearQuery([cts.wordQuery("cat", ["lang=en"], 1), cts.wordQuery("dog", ["lang=en"], 1)], 5, ["unordered"], 1), cts.wordQuery("mouse", ["lang=en"], 1) ], ["unordered"])
// Using bindings var bindings = { title: cts.elementReference('title'), by: 'person-field', cat: function(operator, values, options) { return cts.collectionQuery(values); }, '': function(operator, values, options) { return cts.jsonPropertyWordQuery('desc', values, ['case-sensitive'], 2); } }; cts.parse('title:grapes by:steinbeck cat:classics california', bindings) ==> cts.andQuery( [cts.elementWordQuery(fn.QName("","title"), "grapes", ["lang=en"], 1), cts.fieldWordQuery("by", "steinbeck", ["lang=en"], 1), cts.collectionQuery("classics"), cts.jsonPropertyWordQuery("desc", "california", ["case-sensitive","lang=en"], 2)], ["unordered"])
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.