通过传递同义词值

时间:2019-06-25 14:50:12

标签: marklogic thesaurus

我正在使用MarkLogic同义词库功能,并在传递thsr.lookup()中的同义词之一时努力获取同义词库条目。

例如:我的词库条目在数据库中为

<entry xmlns="http://marklogic.com/xdmp/thesaurus">
 <term>Car</term>
 <part-of-speech>noun</part-of-speech>
 <synonym>
  <term>Ford</term>
  <part-of-speech>noun</part-of-speech>
 </synonym>
 <synonym>
  <term>automobile</term>
  <part-of-speech>noun</part-of-speech>
 </synonym>
 <synonym>
  <term>Fiat</term>
  <part-of-speech>noun</part-of-speech>
 </synonym>

现在,当我以以下方式执行功能时:

thsr.lookup('/thesaurusDoc.xml', 'Car')

我按预期得到了上面的入口元素。

但是当我尝试通过同义词查找时,请说:

thsr.lookup('/thesaurusDoc.xml', 'Fiat')

它不返回任何内容。

您能告诉我我在做什么错吗, 如果同义词库功能不支持通过同义词进行查找,是否建议任何替代方法?

注意:我正在使用Marklogic Server Side Javascript函数,并且ML版本是9.0-8.1

我期望将entry元素重新获得。

2 个答案:

答案 0 :(得分:0)

以下查找是否更接近满足要求?

thsr.queryLookup('/thesaurusDoc.xml', cts.wordQuery('Fiat'))

另请参阅https://docs.marklogic.com/thsr.queryLookup

希望有帮助,

答案 1 :(得分:0)

您需要反向查找,但这从未实现。但是,您自己浏览同义词库并不难。对于完全匹配,您可以执行以下操作:

doc("/thesaurusDoc.xml")
  /thsr:thesaurus/thsr:entry
    [thsr:synonym/thsr:term eq "Fiat"]

或者如果您想使用查询:

doc("/thesaurusDoc.xml")
  /thsr:thesaurus/thsr:entry
    [cts:contains(thsr:synonym/thsr:term, cts:word-query("Fiat"))]

HTH!

相关问题