Reputation: 111
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.
Upvotes: 1
Views: 126
Reputation: 20414
Looking back at the older answers, there is a certain elegance in being able to leverage thsr functions. A fairly straight-forward trick would be to just build a second thesaurus out of the first one, that flips around the terms, and their synonyms. So you get term 'Ford' with 'Car' as synonym.
Granted, if a reverse lookup could be added to thsr, that would have been even better.
HTH!
Upvotes: 0
Reputation: 20414
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!
Upvotes: 1
Reputation: 7335
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,
Upvotes: 0