2

When i am using a cts:search in XQuery i can sort quite easily by accessing the elements of the document.

cts:search(
  fn:doc(), 
  cts:directory-query("/textdocuments/"), 
  cts:index-order(cts:element-reference(xs:QName("title")), "ascending")
)

The issue is that the value i want to use for sorting is contained in another document and the one in the found document is only a reference. E.g. The title hast to be translated, the translation is stored in a separate document and i want to sort after the translation. In SQL the solution would be to perform an inner join and then sort after the joined value. Is a similar solution possible?

I already tried using the Order part of a FLWOR expression and while this is working it is not optimal in performance since it requires loading all documents while i only want to load the first 20.

1 Answers1

1

Okay, so you have the main text documents and a separate document with the translation of the title. In a relational database, as you've noted, the common approach is to have another table do a join. In MarkLogic, the likely best approach is to move those translated titles into the documents that they are a reference for. MarkLogic is generally optimized for sorting on content in the target documents.

<doc>
  <title>My Title</title>
  <title-de>My Title in German</title-de>
  <title-fr>My Title in French</title-fr>
  <content>...</content>
</doc>

I'm not getting into any language-specific search/tokenization/etc here, just bringing together the data you want to work with.

It's worth noting that another approach is to use TDE and the Optic API. You could create a views on your primary documents and your documents with translated titles, do a join, and sort. Without knowing the particulars, it's hard to say for certain, but I'd expect the first approach would be better.

Dave Cassel
  • 8,352
  • 20
  • 38
  • I do not think that moving the data into the documents is a feasible solution because there are multiple titles in multiple documents referring to one translation. I will try working out a solution with TDE. – Alexander Holland May 08 '20 at 05:11