Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marklogic Rest API for directory-query

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?

like image 207
Farouk Alhassan Avatar asked Jan 05 '23 16:01

Farouk Alhassan


1 Answers

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

like image 92
kcoleman Avatar answered Feb 08 '23 04:02

kcoleman