jsearch.byExample( qbe as objectOrNode ) as cts.query
Constructs a cts.query working by example.
Parameters | |
---|---|
qbe | A JavaScript object, JSON node, or XML node that expresses query criteria using Query By Example (QBE) syntax. |
// Matches documents where the "author" JSON property has the value "Mark Twain" const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.documents() .where( jsearch.byExample({author: 'Mark Twain'}) ) .result()
// Match all the following conditions: // - The "title" JSON property has the value "adventures of tom sawyer" // - The "author" JSON property contains the term "mark" within 2 terms of // the term "twain" // - The "format" JSON property within "edition" property has the value // "paperback" or the value "hardback" // - The "price" JSON property value is less than 10.00 and greater or // or equal to 8.00 jsearch.byExample({ "title": { "$value": "adventures of tom sawyer", "$exact": false }, "$near": [ { "author": { "$word": "mark" } }, { "author": { "$word": "twain" } } ], "$distance": 2, "edition": { "$or" : [ { "format": "paperback" }, { "format": "hardback" } ] }, "$and": [ {"price": { "$lt": 10.00 }}, {"price": { "$ge": 8.00 }} ] })