可以在 MarkLogic JSearch 中使用持久搜索选项吗?
Can Persistent Search Options be Used in MarkLogic JSearch?
是否可以在 JSearch 中使用预定义的持久搜索选项,类似于搜索 REST API?翻阅文档,我无法找到它。
JSearch:https://docs.marklogic.com/guide/search-dev/javascript
查询选项:https://docs.marklogic.com/guide/search-dev/query-options
谢谢!
不直接。您将不得不遍历这些选项,并使用各个方面和您自己构建搜索。不过也不会太难。下面是一个快速尝试。我通过 GET /v1/config/query/all?format=json
下载了现有的搜索选项,并隔离了一些路径索引方面。这里有一些遍历它们并生成方面值的代码:
'use strict';
const jsearch = require('/MarkLogic/jsearch.sjs');
function reference(c) {
if (c.range) {
if (c.range['path-index']) {
return cts.pathReference(c.range['path-index'].text)
}
}
}
const options = {
"options": {
"constraint": [{
"name": "Auteur",
"range": {
"type": "xs:string",
"facet": true,
"collation": "http://marklogic.com/collation/codepoint",
"facet-option": ["limit=10", "frequency-order", "descending"],
"path-index": {
"text": "*:meta[@name = 'Author']/@content"
}
}
}, {
"name": "ContentType",
"range": {
"type": "xs:string",
"facet": true,
"collation": "http://marklogic.com/collation/codepoint",
"facet-option": ["limit=10", "frequency-order", "descending"],
"path-index": {
"text": "*:meta[@name = 'content-type']/@content"
}
}
}]
}
};
const facets = options.options.constraint.filter(c => c.range);
jsearch.facets(
facets.map(f => {
let ref = reference(f);
if (ref) {
return jsearch.facet(f.name, ref);
}
}).filter(f => f)
).result('iterator');
HTH!
是否可以在 JSearch 中使用预定义的持久搜索选项,类似于搜索 REST API?翻阅文档,我无法找到它。
JSearch:https://docs.marklogic.com/guide/search-dev/javascript
查询选项:https://docs.marklogic.com/guide/search-dev/query-options
谢谢!
不直接。您将不得不遍历这些选项,并使用各个方面和您自己构建搜索。不过也不会太难。下面是一个快速尝试。我通过 GET /v1/config/query/all?format=json
下载了现有的搜索选项,并隔离了一些路径索引方面。这里有一些遍历它们并生成方面值的代码:
'use strict';
const jsearch = require('/MarkLogic/jsearch.sjs');
function reference(c) {
if (c.range) {
if (c.range['path-index']) {
return cts.pathReference(c.range['path-index'].text)
}
}
}
const options = {
"options": {
"constraint": [{
"name": "Auteur",
"range": {
"type": "xs:string",
"facet": true,
"collation": "http://marklogic.com/collation/codepoint",
"facet-option": ["limit=10", "frequency-order", "descending"],
"path-index": {
"text": "*:meta[@name = 'Author']/@content"
}
}
}, {
"name": "ContentType",
"range": {
"type": "xs:string",
"facet": true,
"collation": "http://marklogic.com/collation/codepoint",
"facet-option": ["limit=10", "frequency-order", "descending"],
"path-index": {
"text": "*:meta[@name = 'content-type']/@content"
}
}
}]
}
};
const facets = options.options.constraint.filter(c => c.range);
jsearch.facets(
facets.map(f => {
let ref = reference(f);
if (ref) {
return jsearch.facet(f.name, ref);
}
}).filter(f => f)
).result('iterator');
HTH!