简体   繁体   中英

Lookup the thesaurus entry by passing the synonym value

I am using the MarkLogic Thesaurus functionality and struggling to fetch the thesaurus entry when passing one of the synonym in thsr.lookup() .

For example : I have my thesuarus entry in the database as

<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>

Now when I execute the function as:

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

I get the above entry element back as expected.

But when I try to lookup via synonym term, say:

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

It doesn't return anything.

Can you please tell what am I doing wrong here and suggest any alternative if thesaurus functionality does not support the lookup via synonym?

Note: I'm using Marklogic Server Side Javascript functions and ML version is 9.0-8.1

I expect to get the entry element back as a result.

Does the following lookup get any closer to meeting the requirement?

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

See also https://docs.marklogic.com/thsr.queryLookup

Hoping that helps,

You need a reverse-lookup, but that was never implemented. It is not difficult to scan through the thesaurus yourself, though. For exact matches you could do something like this:

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

or if you want to use a query:

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

HTH!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM