i fix query on api using nodejs library, lost facet in story.
initially, query (with facet) done querybuilder.
var config = require('./config'); var db marklogic.createdatabaseclient(config.marklogic); var qb = marklogic.querybuilder; var queryelements = [ qb.directory('/product/'), qb.word('brand', 'mybrand') /* add optional conditions here */ ]; // facets var facetquery = qb.where(); facetquery.optionsname = 'search_option'; facetquery.view = 'facets'; facetquery.search = { query: qb.and.apply(qb, queryelements) }; return db.documents.query(facetquery).result(function(documents) { console.log(json.stringify(documents, null, 4)); });
this query return wrong data in case, change xpath query.
var config = require('./config'); var db marklogic.createdatabaseclient(config.marklogic); var query = 'xdmp:directory("/product")[ attr1 eq "" /* , optional conditions */]/languages[ code eq "es_es" , content/category eq "something" /* , optional conditions */] ! root(.)'; return db.xqueryeval(query, {}) .result(function(results) { console.log(json.stringify(results, null, 2)); });
the query works well, but, now, need add facets keep compatibility. searched how add facet on xpath query nodejs library (documentation, example, tuto, ...) haven't found anyhing.
do have idea how can ?
thx
if use internal properties of builder objects instead of documented functions, you're taking risk because internal properties change @ time, breaking code.
for instance, if want specify query, can call function instead of assigning properties:
const query = qb.where(queryelements);
if want create facets, should use facet() , calculate() functions -- see:
http://docs.marklogic.com/guide/node-dev/search#id_74030
facets built entirely out of indexes -- that's way implement facets performance @ scale -- , can filtered queries instead of xpaths.
Comments
Post a Comment