4

I have the following XQuery which I use to fetch documents for a directory.

xquery version "1.0-ml";

cts:search(fn:collection(), cts:directory-query("/Path/To/Docs/", "infinity"))

Now I need to translate this into a REST call but I can't seem to crack it following the documentation on this page.

https://docs.marklogic.com/REST/GET/v1/search

Update:

using the Jersey REST API, It tried this but got 406 Error

String query =  "{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}";

String encodedQuery = URLEncoder.encode(query, "UTF-8");
WebTarget target = searchWebTarget.queryParam("structuredQuery", encodedQuery);

final Response response = target.request().get();

Any ideas?

Farouk Alhassan
  • 3,780
  • 9
  • 51
  • 74

2 Answers2

6

As David said, you don't need to use structured query for this purpose, but in case you have future need:

I believe your original issue was that this is not a well-formed structured query:

{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}

You're missing the top level "query" property. You can find an example of a fully formed structured query that uses directory-query here:

http://docs.marklogic.com/guide/search-dev/structured-query#id_97452

Also, you're probably already aware, but there is a native Java API that sits atop the REST API. You can learn more about this API here:

https://docs.marklogic.com/javadoc/client/index.html

http://docs.marklogic.com/guide/java

kcoleman
  • 666
  • 3
  • 8
3

Constraining by directory is a query parameter directly on the search API. NO other notation needed.

See the docs here: https://docs.marklogic.com/REST/GET/v1/search

  • When I send this commadd https://[marklogic-host]:8801/v1/search?collection=&directory=/Path/to/Doc/ I get a response but the uri of the content it is returning do not start with /Path/to/Doc/ but something completely different – Farouk Alhassan Jul 22 '16 at 13:54
  • Can you provide an example that will match the above xquery? How will the REST url look like for the above Xquery? – Farouk Alhassan Jul 22 '16 at 13:55
  • 1
    Solved by url encoding the directory path. Thanks – Farouk Alhassan Jul 22 '16 at 14:57