Search samples
Basics
Almost all methods use QueryParams. Here are some tips about how to use it.
Variables | Type | Allow wildcards | Restrictions | Description |
---|---|---|---|---|
domain |
long |
No. |
Available values:
By default the value is set to QueryParams.DOCUMENT. For searching documents and folders use value:
|
Restricts the search to node types. |
author |
String |
No. |
Value must be a valid userId. |
Filters by the creator user. |
name |
String |
Yes. |
|
Filters by node name. |
title |
String |
Yes. |
Filters by title. | |
keywords |
Set<String> |
Yes. |
|
Filters by keywords. |
categories |
Set<String> |
No. |
Values should be a category UUID; do not use a path value. |
Filters by categories. |
content |
Yes. |
Filters by binary content. |
||
mimeType |
No. |
Value should be a valid and registered MIME type. Only can be applied to documents node. |
Filters by document MIME type. | |
language |
No. |
Value should be a valid language. Only can be applied to documents node. |
Filters by document language. |
|
folder |
No. |
When empty, the "/okm:root" node is used by default. Value should be a valid UUID; do not use a path value. |
Filters by a folder. |
|
folderRecursive |
Boolean |
No. |
It only makes sense to set this variable to true when the folder variable is not empty. |
Enables recursive filtering by a folder. |
lastModifiedFrom |
Calendar |
No. |
Filters nodes created after a date. |
|
lastModifiedTo |
Calendar |
No. |
Filters nodes created before a date. |
|
mailSubject |
String |
Yes. |
Only applies to mail nodes. |
Filters by the mail subject field. |
mailFrom |
String |
Yes. |
Only applies to mail nodes. |
Filters by the mail from field. |
mailTo |
Yes. |
Only applies to mail nodes. |
Filters by the mail to field. |
|
notes |
Yes. |
Filters by notes. |
||
properties |
Map<String, String> |
Yes for almost all. |
On metadata field values like "date", wildcards cannot be applied. The map of the properties is composed of pairs: ('metadata_field_name','metadata_field_value') For example:
Filtering by range of dates:
When filtering by a range of dates you must set both values (from and to); otherwise the filter will be ignored by OpenKM. To filter by a metadata field of type multiple like this:
You should do:
Where "one" and "two" are valid values and the character ";" is used as a separator. |
Filters by metadata group values. |
The search operation is performed using only AND logic. |
Wildcard examples:
Variable | Example | Description |
---|---|---|
name |
test*.html |
Any document that starts with "test" and ends with ".html". |
name |
test?.html |
Any document that starts with "test" followed by a single character and ends with ".html". |
name |
?test* |
Any document where the first character doesn't matter but is followed by "test". |
Suggested code sample
First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
Then you should log in using the method "login". You can access the "login" method from the webservice object "ws" as shown below:
ws.login(user, password);
Once you are logged in with the webservices, the session is kept in the webservice object. Then you can use the other API methods.
At this point you can use all the Search methods from the "search" class as shown below:
ws.search.find(qParams, null)
Methods
find
Description:
Method | Return values | Description |
---|---|---|
find(QueryParams queryParams, String propertiesPlugin) |
List<QueryResult> |
Returns a list of results filtered by the values of the queryParams parameter. |
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. Retrieving entire objects (Document, Folder, Record, Mail) from REST can take a lot of time - marshalling and unmarshalling - while you are only interested in using a few object variables. If this is your case, you can use NodeProperties classes to retrieve the object variables you really need. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
for (QueryResult qr : ws.search.find(params, null)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
find
Description:
Method | Return values | Description |
---|---|---|
find(QueryParams queryParams, String sortField, boolean sortReverse, String propertiesPlugin) |
List<QueryResult> |
Returns a list of results filtered by the values of the queryParams parameter. |
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. Available sortField values:
Retrieving entire objects (Document, Folder, Record, Mail) from REST can take a lot of time - marshalling and unmarshalling - while you are only interested in using a few object variables. If this is your case, you can use NodeProperties classes to retrieve the object variables you really need. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;
import com.openkm.sdk4j.bean.SearchSortField;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
for (QueryResult qr : ws.search.find(params, SearchSortField.LAST_MODIFIED, true, null)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBasePaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBasePaginated(QueryParams queryParams, int offset, int limit) |
SimpleNodeBaseResultSet |
Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter. |
Because the results of the findSimpleNodeBasePaginated method are objects of type SimpleNodeBase, this method is about 60?70% faster than the other search methods (these metrics should be taken as indicative values because they depend on hardware and the specific scenario where the application is running). The other search methods return objects of type Node, which come with full node data. The SimpleNodeBase object provides less data but in most cases should be enough. Especially when the limit is a higher value, you will appreciate the difference in performance. The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
SimpleNodeBaseResultSet rs = ws.search.findSimpleNodeBasePaginated(params, 20, 10);
System.out.println("Total results: " + rs.getTotal());
for (SimpleNodeBase sn : rs.getResults()) {
System.out.println(sn);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBasePaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBasePaginated(QueryParams queryParams, String sortField, boolean sortReverse, int offset, int limit) |
SimpleNodeBaseResultSet |
Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter. |
Because the results of the findSimpleNodeBasePaginated method are objects of type SimpleNodeBase, this method is about 60-70% faster than the other search methods ( these metrics should be taken as orientative values because depends on hardware and the specific scenario where application is running). The other search methods returns objects of type Node what comes with a full node data, the SimpleNodeBase object provide less data but in almost cases should be enought. Specially when the limit is a higher value you will appreciate the difference in the perfomance. The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
Available sortField values:
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
SimpleNodeBaseResultSet result = ws.search.findSimpleNodeBasePaginated(params, SearchSortField.AUTHOR, true, 0, 10);
System.out.println("Total: " + result.getTotal());
for (SimpleNodeBase nodeBase : result.getResults()) {
if (nodeBase != null) {
System.out.println(nodeBase.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBasePaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBasePaginated(QueryParams queryParams, String sortField, boolean sortReverse, int offset, int limit, String pluginName) |
SimpleNodeBaseResultSet |
Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter. |
Because the results of the findSimpleNodeBasePaginated method are objects of type SimpleNodeBase, this method is about 60-70% faster than the other search methods ( these metrics should be taken as orientative values because depends on hardware and the specific scenario where application is running). The other search methods returns objects of type Node what comes with a full node data, the SimpleNodeBase object provide less data but in almost cases should be enought. Specially when the limit is a higher value you will appreciate the difference in the perfomance. The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
Available sortField values:
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
SimpleNodeBaseResultSet result = ws.search.findSimpleNodeBasePaginated(params, SearchSortField.AUTHOR, true, 0, 10, "com.openkm.plugin.search.TestNodeSearch");
System.out.println("Total: " + result.getTotal());
for (SimpleNodeBase nodeBase : result.getResults()) {
if (nodeBase != null) {
System.out.println(nodeBase.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getCategorizedDocuments
Description:
Method | Return values | Description |
---|---|---|
getCategorizedDocuments(String categoryId) |
List<Document> |
Retrieves a list of all documents related with a category. |
The values of the categoryId parameter should be a category folder UUID. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (Document doc : ws.search.getCategorizedDocuments("58c9b25f-d83e-4006-bd78-e26d7c6fb648")) {
System.out.println(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
saveSearch
Description:
Method | Return values | Description |
---|---|---|
saveSearch(QueryParams params) |
Long |
Saves a search parameters. |
The queryName variable of the params parameter must be initialized. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
for (QueryResult qr : ws.find(qParams, null)) {
System.out.println(qr);
}
// Save the search to be used later
qParams.setQueryName("sample search");
ws.search.saveSearch(qParams);
} catch (Exception e) {
e.printStackTrace();
}
}
}
updateSearch
Description:
Method | Return values | Description |
---|---|---|
updateSearch(QueryParams params) |
void |
Updates previously saved search parameters. |
Only a saved search created by the same user who is executing the method can be updated. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (QueryParams qParams : ws.getAllSearchs()) {
if (qParams.getQueryName().equals("sample search")) {
// Change some value.
qParams.setName("admin*.html");
ws.search.updateSearch(qParams);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getSearch
Description:
Method | Return values | Description |
---|---|---|
getSearch(int qpId) |
QueryParams |
Gets saved search parameters. |
Only can be retrieved as a saved search created by the same user who's executing the method. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
int qpId = 1; // Some valid search id
QueryParams qParams = ws.search.getSearch(qpId);
System.out.println(qParams);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getAllSearches
Description:
Method | Return values | Description |
---|---|---|
getAllSearches() |
List<QueryParams> |
Retrieves a list of all saved search parameters. |
Only will be retrieved the list of the saved searches created by the same user who's executing the method. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (QueryParams qParams : ws.search.getAllSearches()) {
System.out.println(qParams);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
deleteSearch
Description:
Method | Return values | Description |
---|---|---|
deleteSearch(int qpId) |
void |
Deletes a saved search parameters. |
Only can be deleted as a saved search created by the same user user who's executing the method. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
int qpId = 1; // Some valid search id
ws.search.deleteSearch(qpId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getSearchConfig
Description:
Method | Return values | Description |
---|---|---|
getSearchConfig(String pluginName) |
NodeSearchConfig |
Return a NodeSearchConfig object. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.NodeSearchConfig;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
NodeSearchConfig nodeSearchConfig = ws.search.getSearchConfig("com.openkm.plugin.search.TestNodeSearch");
System.out.println(nodeSearchConfig);
} catch (Exception e) {
e.printStackTrace();
}
}
}
findAllDefaultByNodeClass
Description:
Method | Return values | Description |
---|---|---|
findAllDefaultByNodeClass(long ncId) |
List<QueryParams> |
Retrieve a list of saved searches of a NodeClass |
Example:
package com.openkm;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
long ncId = 1;
List<QueryParams> results = ws.search.findAllDefaultByNodeClass(ncId);
for (QueryParams params : results) {
System.out.println(params);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQuery
Description:
Method | Return values | Description |
---|---|---|
findByQuery(String query, String propertiesPlugin) |
List<QueryResult> |
Returns a list of results filtered by the query parameter. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
import java.util.List;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<QueryResult> results = ws.search.findByQuery("keyword:test AND name:t*.pdf", null);
for (QueryResult qr : results) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQuery
Description:
Method | Return values | Description |
---|---|---|
findByQuery(String query, String sortField, boolean sortReverse, String propertiesPlugin) |
List<QueryResult> |
Returns a list of results filtered by the query parameter. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. Available sortField values:
The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
import java.util.List;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
List<QueryResult> results = ws.search.findByQuery("keyword:test AND name:t*.pdf", SearchSortField.NAME, true, null);
for (QueryResult qr : results) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBaseByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBaseByQueryPaginated(String query, int offset, int limit) |
SimpleNodeBaseResultSet |
Returns a list of paginated results filtered by the values of the query parameter. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.SimpleNodeBase;
import com.openkm.sdk4j.bean.SimpleNodeBaseResultSet;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
SimpleNodeBaseResultSet result = ws.search.findSimpleNodeBaseByQueryPaginated("text:grial AND name:t*.pdF", 0, 10);
for (SimpleNodeBase nodeBase : result.getResults()) {
if (nodeBase != null) {
System.out.println(nodeBase.toString());
}
}
System.out.println("Total: " + result.getTotal());
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBaseByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBaseByQueryPaginated(String query, String sortField, boolean sortReverse, int offset, int limit) |
SimpleNodeBaseResultSet |
Returns a list of paginated results filtered by the values of the query parameter. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. Available sortField values:
The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.*;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
SimpleNodeBaseResultSet result = ws.search.findSimpleNodeBaseByQueryPaginated("text:grial AND name:t*.pdF", SearchSortField.NAME, true, 0, 10);
System.out.println("Total: " + result.getTotal());
for (SimpleNodeBase nodeBase : result.getResults()) {
if (nodeBase != null) {
System.out.println(nodeBase.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadata
Description:
Method | Return values | Description |
---|---|---|
findWithMetadata(QueryParams queryParams, String propertiesPlugin, List<String> groups) |
List<QueryResult> |
Returns a list of results with metadata values filtered by the queryParams parameter. |
Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need. |
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:consulting");
for (QueryResult qr : ws.search.findWithMetadata(qParams, null, groups)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadata
Description:
Method | Return values | Description |
---|---|---|
findWithMetadata(QueryParams queryParams, String sortField, boolean sortReverse, String propertiesPlugin, List<String> groups) |
List<QueryResult> |
Returns a list of results with metadata values filtered by the queryParams parameter. |
Available sortField values:
Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.SearchSortField;
import com.openkm.sdk4j.impl.OKMWebservices;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:consulting");
for (QueryResult qr : ws.search.findWithMetadata(params, SearchSortField.NAME, true, null, groups)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadataPaginated
Description:
Method | Return values | Description |
---|---|---|
findWithMetadataPaginated(QueryParams queryParams, int offset, int limit, String propertiesPlugin, List<String> groups) |
ResultSet |
Returns a list of paginated results with metadata values filtered by the queryParams parameter. |
The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. The parameter "groups" must be valid metadata group names. For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
Retrieving entire objects (Document, Folder, Record, Mail) from REST can take a lot of time - the marshalling and unmarshalling processes - while you are only interested in using a few object variables. If it's your case you can use NodeProperties classes for retrieving the object variables that you really need. |
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:consulting");
ResultSet rs = ws.search.findWithMetadataPaginated(qParams, 0, 10, null, groups);
System.out.println("Total results: " + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadataPaginated
Description:
Method | Return values | Description |
---|---|---|
findWithMetadataPaginated(QueryParams queryParams, int offset, int limit, String propertiesPlugin, List<String> groups) |
ResultSet |
Returns a list of paginated results with metadata values filtered by the queryParams parameter. |
The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. The parameter "groups" must be valid metadata group names. Available sortField values:
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
Retrieving entire objects (Document, Folder, Record, Mail) from REST can take a lot of time - the marshalling and unmarshalling processes - while you are only interested in using a few object variables. If it's your case you can use NodeProperties classes for retrieving the object variables that you really need. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;
import com.openkm.sdk4j.bean.SearchSortField;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
ResultSet rs = ws.search.findWithMetadataPaginated(params, SearchSortField.AUTHOR, true, 0, 10, null, groups);
System.out.println("Total results: " + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
csvExport
Description:
Method | Return values | Description |
---|---|---|
csvExport(String token, String lang, QueryParams queryParams, boolean compact) |
InputStream |
Export as a csv a list of results filtered by the values of the queryParams parameter. |
The parameter lang must be ISO 639-1 compliant. More information at: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.impl.OKMWebservices;
import org.apache.commons.io.IOUtils;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
QueryParams params = new QueryParams();
params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
params.setName("test*");
InputStream is = ws.search.csvExport("es-ES", params, false);
OutputStream fos = new FileOutputStream("/home/openkm/okm/export.csv");
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}