MarkLogic JSearch可以使用持久化的搜索选项吗?

问题描述 投票:1回答:1

是否可以在JSearch中使用预定义的、持久的搜索选项,类似于搜索REST API?翻阅文档,我没能找到它。

JSearch。https:/docs.marklogic.comguidesearch-devjavascript。

查询选项。https:/docs.marklogic.comguidesearch-devquery-options。

谢谢你!请问是否可以在JSearch中使用预先定义的、持久的搜索选项,类似于搜索REST API?

marklogic
1个回答
1
投票

不是直接的。你必须遍历这些选项,然后自己构建搜索与面和所有。不过这不会太难。下面是一个快速的尝试。我下载了现有的搜索选项,通过 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!

© www.soinside.com 2019 - 2024. All rights reserved.