5.5.4. Search for data and syntax examples

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

CMIS supports SQL queries for more handful content search. Query service can handle both GET and POST requests. URL for query consists of the repository name and the "/query" method name. The GET request must contain query as a parameter named "q". In case of the POST, query must be located in request body.

Note

You need to enable query support by following CMIS Add-on configuration section.

For more detailed instructions how to construct queries, refer to the Query examples section.

Using Java

 import org.apache.commons.httpclient.HttpClient;

 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 String url = "http://localhost:8080/rest/private/cmisatom/";
 url += repository;
 url += "/query/";
 HttpClient client = new HttpClient();
 client.getHttpConnectionManager().
 getParams().setConnectionTimeout(10000);
 PostMethod post = new PostMethod(url);
 String s = "<?xml version='1.0' encoding='utf-8'?>"
     + "<cmis:query xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://docs.oasis-open.org/ns/cmis/core/200908/'>"
     + "<cmis:statement>SELECT * FROM cmis:document</cmis:statement>"
     + "<cmis:maxItems>10</cmis:maxItems>"
     + "<cmis:skipCount>0</cmis:skipCount>"
     + "<cmis:searchAllVersions>true</cmis:searchAllVersions>"
     + "<cmis:includeAllowableActions>true</cmis:includeAllowableActions>"
     + "</cmis:query>";
 RequestEntity entity = new StringRequestEntity(s, "text/xml","utf-8");
 try {
   post.setRequestEntity(entity);
   int result = client.executeMethod(post);
   final String strResponse = post.getResponseBodyAsString();
   // use response...
 } finally {
   post.releaseConnection();
 }

Using JavaScript

 var url = "http://localhost:8080/rest/private/cmisatom/";

 url += repository;
 url += "/query/";
 var params = {};

 params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
 params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(someQuery);
 gadgets.io.makeRequest(url, handler, params);
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus