MarkLogic 10 Product Documentation
jsearch.byExample

jsearch.byExample(
   qbe as objectOrNode
) as cts.query

Summary

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.

Usage Notes

Use this method to construct a cts.query using syntax that closely resemble the content you want to match. The syntax is based on Query By Example (QBE), but contains some differences. For details, see Differences Between byExample and QBE in the Search Developer's Guide.

See Also

Example


// 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()
   

Example


// 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 }}
  ]
})
   
Powered by MarkLogic Server | Terms of Use | Privacy Policy