Frage

I am using MarkLogic THSR functions to create synonym of "Company" term. I am able to get desired result. When I am searching on the basis of "Company" term, I am getting text "Company" highlighted only. But, I need all the synonyms highlighted.

I am using cts:highlight to highlight text when displaying result.

My thesaurus XML is as under:

<thesaurus  xmlns="http://marklogic.com/xdmp/thesaurus">
  <entry>
    <term>Company</term>
    <synonym>
      <term>Services</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Industry</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Firm</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Business</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Corporation</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>House</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Establishment</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Agency</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Office</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Bureau</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Organization</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Institution</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Operation</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Enterprise</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Venture</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
    <synonym>
      <term>Undertaking</term>
      <part-of-speech>noun</part-of-speech>
    </synonym>
  </entry>
</thesaurus>

Is there any other way to highlight these things or I am doing anything wrong? Please help me.

My query to use thesaurus is as under:

cts:search(//TEXT, thsr:expand(cts:word-query("TEXT"),  thsr:lookup("/myThsrDocs/syn.xml", "TEXT"),(),(),()))
War es hilfreich?

Lösung

Typically you'd use https://docs.marklogic.com/thsr:expand to expand your query, then pass the results as XML to https://docs.marklogic.com/search:resolve which would do the highlighting.

search:resolve(
  document {
    thsr:expand(
      cts:word-query("Company"), $THESAURUS-ENTRIES, (), (), ()) }/*)

The thsr:expand function uses your initial cts:query item and your thesaurus entries to write an expanded query. The document { ... }/* expression turns that cts:query item into an XML element, which is what search:resolve expects.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top