lib/query-builder.js
function withOptions() {
  /*jshint validthis:true */
  var self = (this instanceof QueryBuilder) ? this : new QueryBuilder();

  // TODO: share with documents.js
  var optionKeyMapping = {
    search:'search-option',     weight:'quality-weight',
    forestNames:'forest',       similarDocs:'return-similar',
    metrics:'return-metrics',   queryPlan:'return-plan',
    debug:'debug',              concurrencyLevel:'concurrency-level',
    categories:true,            txid:true
  };

  var withOptionsClause = {};
  if (0 < arguments.length) {
    var arg = arguments[0];
    var argKeys = Object.keys(arg);
    for (var i=0; i < argKeys.length; i++) {
      var key = argKeys[i];
      if (optionKeyMapping[key] !== void 0) {
        var value = arg[key];
        if (value !== void 0) {
          withOptionsClause[key] = value;
        } else {
          throw new Error('empty options value for '+key);
        }
      } else {
        throw new Error('unknown option '+key);
      }
    }
  }
  self.withOptionsClause = withOptionsClause;

  return self;
}
function withOptions() {
  /*jshint validthis:true */
  var self = (this instanceof QueryBuilder) ? this : new QueryBuilder();

  // TODO: share with documents.js
  var optionKeyMapping = {
    search:'search-option',     weight:'quality-weight',
    forestNames:'forest',       similarDocs:'return-similar',
    metrics:'return-metrics',   queryPlan:'return-plan',
    debug:'debug',              concurrencyLevel:'concurrency-level',
    categories:true,            txid:true
  };

  var withOptionsClause = {};
  if (0 < arguments.length) {
    var arg = arguments[0];
    var argKeys = Object.keys(arg);
    for (var i=0; i < argKeys.length; i++) {
      var key = argKeys[i];
      if (optionKeyMapping[key] !== void 0) {
        var value = arg[key];
        if (value !== void 0) {
          withOptionsClause[key] = value;
        } else {
          throw new Error('empty options value for '+key);
        }
      } else {
        throw new Error('unknown option '+key);
      }
    }
  }
  self.withOptionsClause = withOptionsClause;

  return self;
}
function withOptions ( ) { /*jshint validthis:true */ var self = ( this instanceof QueryBuilder ) ? this : new QueryBuilder ( ) ; // TODO: share with documents.js var optionKeyMapping = { search : 'search-option' , weight : 'quality-weight' , forestNames : 'forest' , similarDocs : 'return-similar' , metrics : 'return-metrics' , queryPlan : 'return-plan' , debug : 'debug' , concurrencyLevel : 'concurrency-level' , categories : true , txid : true } ; var withOptionsClause = { } ; if ( 0 < arguments . length ) { var arg = arguments [ 0 ] ; var argKeys = Object . keys ( arg ) ; for ( var i = 0 ; i < argKeys . length ; i ++ ) { var key = argKeys [ i ] ; if ( optionKeyMapping [ key ] !== void 0 ) { var value = arg [ key ] ; if ( value !== void 0 ) { withOptionsClause [ key ] = value ; } else { throw new Error ( 'empty options value for ' + key ) ; } } else { throw new Error ( 'unknown option ' + key ) ; } } } self . withOptionsClause = withOptionsClause ; return self ; }
Sets the withOptions clause of a built query to configure the query;
takes a configuration object with the following named parameters.
This function may be called on the result of building a query. When the
'debug', 'metrics', 'queryPlan', or 'similarDocs' parameter is set, a
search summary object will be returned along with the result documents.
When 'categories' is set to 'none', only a search summary is returned.
@method
@since 1.0
@memberof queryBuilder#
@param {documents.categories}  [categories] - the categories of information
to retrieve for the result documents
@param {number} [concurrencyLevel] - the maximum number of threads to use to calculate facets
@param {string|string[]} [forestNames] - the ids of forests providing documents
for the result set
@param {...string} [search] - <a href="https://docs.marklogic.com/guide/search-dev/appendixa#id_77801">options</a>
modifying the default behaviour of the query
@param {string|transactions.Transaction}  [txid] - a string
transaction id or Transaction object identifying an open
multi-statement transaction
@param {number} [weight] - a weighting factor between -16 and 64
@param {boolean} [debug] - whether to return query debugging
@param {boolean} [metrics] - whether to return metrics for the query performance
@param {boolean} [queryPlan] - whether to return a plan for the execution of the query
@param {boolean} [similarDocs] - whether to return a list of URIs for documents
similar to each result
@returns {queryBuilder.BuiltQuery} a built query
Sets the withOptions clause of a built query to configure the query ; takes a configuration object with the following named parameters . This function may be called on the result of building a query . When the debug metrics queryPlan or similarDocs parameter is set a search summary object will be returned along with the result documents . When categories is set to none only a search summary is returned .