我使用nodejs库在我的API上修复了一个查询,但我失去了故事中的方面。Marklogic(Nodejs API) - 在XPath查询中添加构面
最初,查询(with facet)是用queryBuilder完成的。
var config = require('./config');
var db marklogic.createDatabaseClient(config.marklogic);
var qb = marklogic.queryBuilder;
var queryElements = [
qb.directory('/product/'),
qb.word('brand', 'myBrand')
/* we 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));
});
此查询在某些情况下返回错误的数据,因此我使用XPath查询进行更改。
var config = require('./config');
var db marklogic.createDatabaseClient(config.marklogic);
var query = 'xdmp:directory("/product")[ attr1 eq "" /* and some optional conditions */]/languages[ code eq "es_ES" and content/category eq "something" /* and some optional conditions */] ! root(.)';
return db.xqueryEval(query, {})
.result(function(results) {
console.log(JSON.stringify(results, null, 2));
});
该查询效果很好,但现在,我需要添加构面以保持兼容性。 我搜索了如何在带有nodejs库(文档,示例,tuto,...)的XPath查询中添加方面,但是我没有找到任何方法。
你知道我能做些什么吗?
THX
我认为你最好的选择是解决你的第一个查询返回错误数据的原因。这样的[查询默认运行](默认情况下,http://docs.marklogic.com/guide/performance/unfiltered#chapter),所以你可以让它运行过滤或者(更好地)以不同的方式配置你的索引。你能否多说一些不正确的结果? –
我在我的文档中有一个对象数组,我需要找到至少有一个匹配条件匹配的对象的文档。如果我使用queryBuilder,我会找到所有对象中某处匹配条件的文档,而不一定在同一个对象中。 目前,我们无法使用queryBuilder对marklogic中的JSON文档进行这种查询。我需要使用XPath查询来为每个对象应用条件 –