1

I want to search in MarkLogic with using term-query in direcories that meet the pattern:

/example/*/folder/

i.e.

/example/foo/folder/
/example/foo/bar/folder/

and so on... I have something like this:

<search xmlns="http://marklogic.com/appservices/search">
  <query>
    <and-query>
      <directory-query>
        <uri>/example/*/folder/</uri>
        <depth>1</depth>
      </directory-query>
      <term-query>
        <text>some text</text>
      </term-query>
    </and-query>
  </query>
</search>

..but unfortunately <directory-query> seems not supporting wildcards in URI. Any idea how to use <directory-query> with wildcards?

Aspir
  • 149
  • 9

1 Answers1

2

You could use cts:uri-match() instead, and then apply those URIs to a cts:document-query():

cts:document-query(cts:uri-match("/directory/*/folder/*"))
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • Coud you also provide snippet in JAVA Api? – Aspir Mar 27 '23 at 14:18
  • cts:uri-match("/directory/*/folder/*" returns files and folders, how return only folders? – Aspir Mar 27 '23 at 14:22
  • The example from Mads is no longer a `cts:directory-query()`. It is now a `cts:document-query()`. The expansion into all documents that would match the wild-carded directory is already done. Therefore, needing to worry about directories is no longer in scope in the sample. – David Ennis -CleverLlamas.com Mar 27 '23 at 14:56