OKMSearch
Basics
Almosts all methods use QueryParams. Here there're some tips about how using 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. |
The value must be a valid userId. |
Filters by creator user. |
name |
String |
Yes. |
|
Filters by node name. |
title |
String |
Yes. |
Filters by title name. | |
keywords |
Set<String> |
Yes. |
|
Filters by keywords. |
categories |
Set<String> |
No. |
Values should be a category UUID, not use path value. |
Filters by categories. |
content |
Yes. |
Filters by binary content. |
||
mimeType |
No. |
The value should be a valid and registered MIME type. Only can be applied to documents node. |
Filters by document MIME type. | |
language |
No. |
The value should be a valid language. Only can be applied to documents node. |
Filters by document language. |
|
folder |
No. |
When empty is used by default "/okm:root" node. The value should be a valid UUID, not use a path value. |
Filters by a folder. |
|
folderRecursive |
Boolean |
No. |
Only has sense to set this variable to true when the variable folder is not empty. |
Enables filter recursively by a folder. |
lastModifiedFrom |
Calendar |
No. |
Filters by nodes created after a date. |
|
lastModifiedTo |
Calendar |
No. |
Filters by nodes created before a date. |
|
mailSubject |
String |
Yes. |
Only apply to mail nodes. |
Filters by mail subject field. |
mailFrom |
String |
Yes. |
Only apply to mail nodes. |
Filters by mail from the field. |
mailTo |
Yes. |
Only apply to mail nodes. |
Filters by mail to the field. |
|
notes |
Yes. |
Filters by notes. |
||
properties |
Map<String, String> |
Yes on almost. |
On metadata field values like "date" can not be applied wilcards. The map of the properties is composed of pairs: ('metadata_field_name','metada_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 from the OpenKM side. To filtering by a metadata field of type multiple like this:
You should do:
Where "one" and "two" are valid values and character ";" is used as separator. |
Filters by metadata group values. |
The search operation is done only by AND logic. |
Wildcard examples:
Variable | Example | Description |
---|---|---|
name |
test*.html |
Any document that starts with characters "test" and ends with characters ".html" |
name |
test?.html |
Any document that starts with the characters "test" followed by a single character and ends with characters ".html" |
name |
?test* |
Any of the documents where the first character doesn't matter but is followed by the characters, "test". |
Methods
find
Description:
Method | Return values | Description |
---|---|---|
find(String token, QueryParams params) |
List<QueryResult> |
Returns a list of results filtered by the values of the queryParams parameter. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
for (QueryResult qr : okmSearch.find(null, qParams)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
find
Description:
Method | Return values | Description |
---|---|---|
find(String token, QueryParams params, 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 process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
for (QueryResult qr : okmSearch.find(null, qParams, "com.openkm.plugin.properties.SimpleNodeProperties")) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
find
Description:
Method | Return values | Description |
---|---|---|
find(String token, QueryParams params, String sortField, boolean sortReverse, String propertiesPlugin) |
List<QueryResult> |
Returns a list of results filtered by the values of the queryParams parameter. |
From version 7.1.27 of OpenKM this method was added 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 process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
for (QueryResult qr : okmSearch.find(null, qParams, "name", true, "com.openkm.plugin.properties.SimpleNodeProperties")) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findPaginated
Description:
Method | Return values | Description |
---|---|---|
findPaginated(String token, QueryParams params, int offset, int limit) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
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:
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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
ResultSet rs = okmSearch.findPaginated(null, qParams, 20, 10);
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findPaginated
Description:
Method | Return values | Description |
---|---|---|
findPaginated(String token, QueryParams params, int offset, int limit, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
The parameter "limit" and "offset" allows 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. 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 - 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
ResultSet rs = okmSearch.findPaginated(null, qParams, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties");
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findPaginated
Description:
Method | Return values | Description |
---|---|---|
findPaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
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:
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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
ResultSet rs = okmSearch.findPaginated(null, qParams, "name", true, 20, 10);
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findPaginated
Description:
Method | Return values | Description |
---|---|---|
findPaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
The parameter "limit" and "offset" allows 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. 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 - 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
ResultSet rs = okmSearch.findPaginated(null, qParams, "name", true, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties");
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadata
Description:
Method | Return values | Description |
---|---|---|
findWithMetadata(String token, QueryParams params, String propertiesPlugin, List<String> groups) |
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. The parameter "groups" is the name metadata group. 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 a few Objects variables. If it's 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:tpl");
for (QueryResult qr : okmSearch.findWithMetadata(null, qParams, "com.openkm.plugin.properties.SimpleNodeProperties",
groups)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadata
Description:
Method | Return values | Description |
---|---|---|
findWithMetadata(String token, QueryParams params, String sortField, boolean sortReverse, String propertiesPlugin, List<String> groups) |
List<QueryResult> |
Returns a list of results filtered by the values of the queryParams parameter. |
From version 7.1.27 of OpenKM this method was added The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. The parameter "groups" is the name metadata group. 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 a few Objects variables. If it's 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:tpl");
for (QueryResult qr : okmSearch.findWithMetadata(null, qParams, "name", true, "com.openkm.plugin.properties.SimpleNodeProperties",
groups)) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findWithMetadataPaginated
Description:
Method | Return values | Description |
---|---|---|
findWithMetadataPaginated(String token, QueryParams params, int offset, int limit, String propertiesPlugin, List<String> groups) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. The parameter "groups" is the name metadata group. 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 - 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
List<String> groups = new ArrayList<>();
groups.add("okg:tpl");
ResultSet rs = okmSearch.findWithMetadataPaginated(null, qParams, 0, 10, "com.openkm.plugin.properties.SimpleNodeProperties", 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(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin, List<String> groups) |
ResultSet |
Returns a list of paginated results filtered by the values of the queryParams parameter. |
The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. The parameter "groups" is the name metadata group. 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 - 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.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
String sortField = "okm:";
boolean sortReverse = false;
List<String> groups = new ArrayList<>();
groups.add("okg:tpl");
ResultSet rs = okmSearch.findWithMetadataPaginated(null, qParams, sortField, sortReverse, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties", groups);
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBasePaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBasePaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin) |
SimpleNodeBaseResultSet |
Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter. |
From version 7.1.19 of OpenKM this method was added The parameter "limit" and "offset" allows 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. 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 - 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.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
import com.openkm.ws.rest.util.SimpleNodeBase;
import com.openkm.ws.rest.util.SimpleNodeBaseResultSet;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
SimpleNodeBaseResultSet resultSet = okmSearch.findSimpleNodeBasePaginated(null, qParams, "name", true, 0, 10);
System.out.println("Total results:" + resultSet.getTotal());
for (SimpleNodeBase simpleNodeBase : resultSet.getResults()) {
System.out.println(simpleNodeBase);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQuery
Description:
Method | Return values | Description |
---|---|---|
findByQuery(String token, String query) |
List<QueryResult> |
Returns a list of paginated results filtered by the value of the query parameter. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (QueryResult qr : okmSearch.findByQuery(null, "text:grial AND name:o*.pdf")) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQuery
Description:
Method | Return values | Description |
---|---|---|
findByQuery(String token, String query, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the value of the query parameter. |
The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (QueryResult qr : okmSearch.findByQuery(null, "text:grial AND name:o*.pdf",
"com.openkm.plugin.properties.SimpleNodeProperties")) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQuery
Description:
Method | Return values | Description |
---|---|---|
findByQuery(String token, String query, String sortField, boolean sortReverse, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the value of the query parameter. |
From version 7.1.27 of OpenKM this method was added The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface. Available sortField values:
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (QueryResult qr : okmSearch.findByQuery(null, "text:grial AND name:o*.pdf", "name", true, "com.openkm.plugin.properties.SimpleNodeProperties")) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findByQueryPaginated(String token, String query, int offset, int limit) |
ResultSet |
Returns a list of paginated results filtered by the value of the query parameter. |
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:
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
ResultSet rs = okmSearch.findByQueryPaginated(null, "text:grial AND name:o*.pdf", 10, 10);
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findByQueryPaginated(String token, String query, int offset, int limit, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the value of the query parameter. |
The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. 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 - 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. The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
ResultSet rs = okmSearch.findByQueryPaginated(null, "text:grial AND name:o*.pdf", 0, 10,
"com.openkm.plugin.properties.SimpleNodeProperties");
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findByQueryPaginated(String token, String query, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin) |
ResultSet |
Returns a list of paginated results filtered by the value of the query parameter. |
The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface. 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 - 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. The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
ResultSet rs = okmSearch.findByQueryPaginated(null, "text:grial AND name:o*.pdf", "name", true, 0, 10,
"com.openkm.plugin.properties.SimpleNodeProperties");
System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) {
System.out.println(qr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findSimpleNodeBaseByQueryPaginated
Description:
Method | Return values | Description |
---|---|---|
findSimpleNodeBaseByQueryPaginated(String token, String query, String sortField, boolean sortReverse, int offset, int limit) |
SimpleNodeBaseResultSet |
Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter. |
From version 7.1.20 of OpenKM this method was added 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:
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. The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
import com.openkm.ws.rest.util.SimpleNodeBase;
import com.openkm.ws.rest.util.SimpleNodeBaseResultSet;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
SimpleNodeBaseResultSet resultSet = okmSearch.findSimpleNodeBasePaginated(null, qParams, "name", true, 0, 10);
System.out.println("Total results:" + resultSet.getTotal());
for (SimpleNodeBase simpleNodeBase : resultSet.getResults()) {
System.out.println(simpleNodeBase);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
saveSearch
Description:
Method | Return values | Description |
---|---|---|
saveSearch(String token, QueryParams params) |
Long |
Saves search parameters. |
The variable queryName of the parameter params should have to be initialized. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
qParams.setName("test*");
// Save the search to be used later
qParams.setQueryName("sample search");
okmSearch.saveSearch(null, qParams);
} catch (Exception e) {
e.printStackTrace();
}
}
}
updateSearch
Description:
Method | Return values | Description |
---|---|---|
updateSearch(String token, QueryParams params) |
void |
Saves a search parameters. |
Only can be updated as a saved search created by the same user user who's executing the method. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (QueryParams qParams : okmSearch.getAllSearches(null)) {
if (qParams.getQueryName().equals("sample search")) {
// Change some value.
qParams.setName("admin*.html");
okmSearch.updateSearch(null, qParams);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getSearch
Description:
Method | Return values | Description |
---|---|---|
getSearch(String token, int qpId) |
QueryParams |
Gets saved search. |
Only can be updated as a saved search created by the same user user who's executing the method. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
int qpId = 1; // Some valid search id
QueryParams qParams = okmSearch.getSearch(null, qpId);
System.out.println(qParams);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getAllSearches
Description:
Method | Return values | Description |
---|---|---|
getAllSearches(String token) |
List<QueryParams> |
Retrieves a list of all saved search. |
Only can be updated as a saved search created by the same user who's executing the method. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (QueryParams qParams : okmSearch.getAllSearches(null)) {
System.out.println(qParams);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
deleteSearch
Description:
Method | Return values | Description |
---|---|---|
deleteSearch(String token, long qpId) |
void |
Deletes a saved search. |
Only can be updated as a saved search created by the same user user who's executing the method. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
int qpId = 1; // Some valid search id
okmSearch.deleteSearch(null, qpId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getKeywordMap
Description:
Method | Return values | Description |
---|---|---|
getKeywordMap(String token, List<String> filter) |
Map<String, Integer> |
Returns a map of keywords with its count value filtered by other keywords. |
Example:
The results filtering by "test" -> "one", "two", "three". The results filtering by "one" -> "test", "two". The results filtering by "two" -> "test", "one". The results filtering by "three" -> "test". The results filtering by "one" and "two" -> "test" |
package com.openkm;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import com.openkm.api.OKMSearch;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
// All keywords without filtering
System.out.println("Without filtering");
Map<String, Integer> keywords = okmSearch.getKeywordMap(null, new ArrayList<String>());
for (String key : keywords.keySet()) {
System.out.println(key + " is used :" + keywords.get(key));
}
// Keywords filtered
System.out.println("Filtering");
keywords = okmSearch.getKeywordMap(null, Arrays.asList("test"));
for (String key : keywords.keySet()) {
System.out.println(key + " is used :" + keywords.get(key));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getCategorizedDocuments
Description:
Method | Return values | Description |
---|---|---|
getCategorizedDocuments(String token, 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 or path. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Document;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Document doc : okmSearch.getCategorizedDocuments(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
System.out.println(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getCategorizedFolders
Description:
Method | Return values | Description |
---|---|---|
getCategorizedFolders(String token, String categoryId) |
List<Folder> |
Retrieves a list of all folders related to a category. |
The values of the categoryId parameter should be a category folder UUID or path. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Folder fld : okmSearch.getCategorizedFolders(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
System.out.println(fld);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getCategorizedMails
Description:
Method | Return values | Description |
---|---|---|
getCategorizedMails(String token, String categoryId) |
List<Mail> |
Retrieves a list of all mails related to a category. |
The values of the categoryId parameter should be a category folder UUID or path. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Mail;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Mail mail : okmSearch.getCategorizedMails(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
System.out.println(mail);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getCategorizedRecords
Description:
Method | Return values | Description |
---|---|---|
getCategorizedRecords(String token, String categoryId) |
List<Record> |
Retrieves a list of all records related to a category. |
The values of the categoryId parameter should be a category folder UUID or path. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Record rec : okmSearch.getCategorizedRecords(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
System.out.println(rec);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getDocumentsByKeyword
Description:
Method | Return values | Description |
---|---|---|
getDocumentsByKeyword(String token, String keyword) |
List<Document> |
Retrieves a list of all documents related to a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Document;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Document doc : okmSearch.getDocumentsByKeyword(null, "test")) {
System.out.println(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getFoldersByKeyword
Description:
Method | Return values | Description |
---|---|---|
getFoldersByKeyword(String token, String keyword) |
List<Folder> |
Retrieves a list of all folders related to a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Folder fld : okmSearch.getFoldersByKeyword(null, "test")) {
System.out.println(fld);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getMailsByKeyword
Description:
Method | Return values | Description |
---|---|---|
getMailsByKeyword(String token, String keyword) |
List<Mail> |
Retrieves a list of all mails related to a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Mail;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Mail mail : okmSearch.getMailsByKeyword(null, "test")) {
System.out.println(mail);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getRecordsByKeyword
Description:
Method | Return values | Description |
---|---|---|
getRecordsByKeyword(String token, String keyword) |
List<Record> |
Retrieves a list of all records related to a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Record rec : okmSearch.getRecordsByKeyword(null, "test")) {
System.out.println(rec);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getDocumentsByPropertyValue
Description:
Method | Return values | Description |
---|---|---|
getDocumentsByPropertyValue(String token, String group, String property, String value |
List<Document> |
Retrieves a list of all documents related with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Document;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Document doc : okmSearch.getDocumentsByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
System.out.println(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getFoldersByPropertyValue
Description:
Method | Return values | Description |
---|---|---|
getFoldersByPropertyValue(String token, String group, String property, String value |
List<Folder> |
Retrieves a list of all folders related with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Folder fld : okmSearch.getFoldersByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
System.out.println(fld);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getMailsByPropertyValue
Description:
Method | Return values | Description |
---|---|---|
getMailsByPropertyValue(String token, String group, String property, String value |
List<Mail> |
Retrieves a list of all mails related with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Mail;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Mail mail : okmSearch.getMailsByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
System.out.println(mail);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getRecordsByPropertyValue
Description:
Method | Return values | Description |
---|---|---|
getRecordsByPropertyValue(String token, String group, String property, String value) |
List<Record> |
Retrieves a list of all records related with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
for (Record rec : okmSearch.getRecordsByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
System.out.println(rec);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findMailPaginated
Description:
Method | Return values | Description |
---|---|---|
findMailPaginated(String token, Map<String, String> filter, String sortField, boolean sortReverse, int type, |
ResultSet |
Returns a list of paginated mail results filtered by the values of the parameters. |
Allowed filter key values are:
Send data value format must be: ISO8601.formatBasic(from)+","+ISO8601.formatBasic(to) Allowed sortField values are:
Allowed type values are:
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:
|
package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
Map<String, String> filter = new HashMap<>();
String sortField = "okm:";
int type = OKMSearch.TYPE_MAIL_ALL;
ResultSet rs = okmSearch.findMailPaginated(null, filter, sortField, false, type, 0, 10);
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 lang, QueryParams queryParams, boolean compact, String filename) |
InputStream |
Export as a csv a list of results filtered by the values of the queryParams parameter. |
Method added from OpenKM version 7.1.27. The parameter lang must be ISO 691-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, "export.csv");
OutputStream fos = new FileOutputStream("/home/openkm/okm/export.csv");
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}