OKMSearch
Basics
Section titled “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: - QueryParams.DOCUMENT - QueryParams.FOLDER - QueryParams.MAIL - QueryParams.RECORD By default the value is set to QueryParams.DOCUMENT. To search documents and folders, use the value: <br>(QueryParams.DOCUMENT | QueryParams.FOLDER) <br> |
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. | |
| keywords | Set |
Yes. | Filters by keywords. | |
| categories | Set |
No. | Values should be a category UUID; do not use a path value. | Filters by categories. |
| content | Yes. | Filters by binary content. | ||
| mimeType | No. | The value should be a valid and registered MIME type. Can only be applied to document nodes. |
Filters by document MIME type. | |
| language | No. | The value should be a valid language. Can only be applied to document nodes. |
Filters by document language. | |
| folder | No. | When empty, the “/okm:root” node is used by default. The 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 apply to mail nodes. | Filters by the mail “from” field. |
| mailTo | Yes. | Only apply to mail nodes. | Filters by the mail “to” field. | |
| notes | Yes. | Filters by notes. | ||
| properties | Map<String, String> | Yes on almost all. | Wildcards cannot be applied to metadata field values like “date”. The map of the properties is composed of pairs: (‘metadata_field_name’,‘metadata_field_value’) For example: javascript<br>Map<String, String> properties = new HashMap();<br>properties.put("okp:consulting.name", "name value");<br>Filtering by range of dates: cs<br>Calendar to = Calendar.getInstance(); // today<br>to.set(0, Calendar.HOUR);<br>to.set(0, Calendar.MINUTE);<br>to.set(0, Calendar.SECOND);<br>to.set(0, Calendar.MILLISECOND);<br>Calendar from = (Calendar) to.clone();<br>from.add(-3, Calendar.DATE); // three days before<br>Map<String,String> properties = new HashMap<>();<br>properties.put("okp:consulting.date", ISO8601.formatBasic(from)+","+ISO8601.formatBasic(to));<br>When filtering by a range of dates you must set both values (from and to); otherwise, the filter will be ignored by the OpenKM side. To filter by a metadata field of type “multiple” like this: cs<br><select label="Multiple" name="okp:consulting.multiple" type="multiple"><br> <option label="One" value="one"/><br> <option label="Two" value="two"/><br> <option label="Three" value="three" /><br></select><br>You should do: bash<br>properties.put("okp:consulting.multiple", "one;two");<br>Where “one” and “two” are valid values and the character “;” is used as a separator. |
Filters by metadata group values. |
Wildcard examples:
| Variable | Example | Description |
|---|---|---|
| name | test*.html | Any document that starts with the characters “test” and ends with the characters “.html”. |
| name | test?.html | Any document that starts with the characters “test” followed by a single character and ends with the characters “.html”. |
| name | ?test* | Any document where the first character doesn’t matter but is followed by the characters “test”. |
Methods
Section titled “Methods”Description:
| Method | Return values | Description |
|---|---|---|
| find(String token, QueryParams params) | List |
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(); } }}Description:
| Method | Return values | Description |
|---|---|---|
| find(String token, QueryParams params, String propertiesPlugin) | List |
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, "com.openkm.plugin.properties.SimpleNodeProperties")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findPaginated
Section titled “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. |
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(); } }}findWithMetadata
Section titled “findWithMetadata”Description:
| Method | Return values | Description |
|---|---|---|
| findWithMetadata(String token, QueryParams params, String propertiesPlugin, List |
List |
Returns a list of results filtered by the values of the queryParams parameter. |
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(); } }}findWithMetadataPaginated
Section titled “findWithMetadataPaginated”Description:
| Method | Return values | Description |
|---|---|---|
| findWithMetadataPaginated(String token, QueryParams params, int offset, int limit, String propertiesPlugin, List |
ResultSet | Returns a list of paginated results filtered by the values of the queryParams parameter. |
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(); } }}findByQuery
Section titled “findByQuery”Description:
| Method | Return values | Description |
|---|---|---|
| findByQuery(String token, String query) | List |
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
Section titled “findByQuery”Description:
| Method | Return values | Description |
|---|---|---|
| findByQuery(String token, String query, String propertiesPlugin) | List |
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", "com.openkm.plugin.properties.SimpleNodeProperties")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findByQuery
Section titled “findByQuery”Description:
| Method | Return values | Description |
|---|---|---|
| findByQuery(String token, String query, String sortField, boolean sortReverse, String propertiesPlugin) | List |
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", "name", true, "com.openkm.plugin.properties.SimpleNodeProperties")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findByQueryPaginated
Section titled “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. |
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
Section titled “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. |
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
Section titled “findByQueryPaginated”Description:
| Method | Return values | Description |
|---|---|---|
| findByQueryPaginated(String token, String query, String sortField, boolean sortReverse, int offset, int limit) | ResultSet | Returns a paginated and sorted list of results filtered by the value of the query parameter. |
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); System.out.println("Total results:" + rs.getTotal());
for (QueryResult qr : rs.getResults()) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findByQueryPaginated
Section titled “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. |
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
Section titled “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. |
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.findSimpleNodeBaseByQueryPaginated(null, "name:test*", "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(); } }}findSimpleNodeBasePaginated
Section titled “findSimpleNodeBasePaginated”Description:
| Method | Return values | Description |
|---|---|---|
| findSimpleNodeBasePaginated(String token, QueryParams params, int offset, int limit) | SimpleNodeBaseResultSet | Returns a paginated list of SimpleNodeBase results filtered by the values of the QueryParams parameter. |
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, 0, 10); System.out.println("Total results:" + resultSet.getTotal());
for (SimpleNodeBase snb : resultSet.getResults()) { System.out.println(snb); } } catch (Exception e) { e.printStackTrace(); } }}saveSearch
Section titled “saveSearch”Description:
| Method | Return values | Description |
|---|---|---|
| saveSearch(String token, QueryParams params) | Long | Saves search parameters. |
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
Section titled “updateSearch”Description:
| Method | Return values | Description |
|---|---|---|
| updateSearch(String token, QueryParams params) | void | Saves search parameters. |
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
Section titled “getSearch”Description:
| Method | Return values | Description |
|---|---|---|
| getSearch(String token, int qpId) | QueryParams | Gets saved search. |
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
Section titled “getAllSearches”Description:
| Method | Return values | Description |
|---|---|---|
| getAllSearches(String token) | List |
Retrieves a list of all saved searches. |
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
Section titled “deleteSearch”Description:
| Method | Return values | Description |
|---|---|---|
| deleteSearch(String token, long qpId) | void | Deletes a saved search. |
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(); } }}getCategorizedDocuments
Section titled “getCategorizedDocuments”Description:
| Method | Return values | Description |
|---|---|---|
| getCategorizedDocuments(String token, String categoryId) | List |
Retrieves a list of all documents related to a category. |
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
Section titled “getCategorizedFolders”Description:
| Method | Return values | Description |
|---|---|---|
| getCategorizedFolders(String token, String categoryId) | List |
Retrieves a list of all folders related to a category. |
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
Section titled “getCategorizedMails”Description:
| Method | Return values | Description |
|---|---|---|
| getCategorizedMails(String token, String categoryId) | List |
Retrieves a list of all mails related to a category. |
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
Section titled “getCategorizedRecords”Description:
| Method | Return values | Description |
|---|---|---|
| getCategorizedRecords(String token, String categoryId) | List |
Retrieves a list of all records related to a category. |
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
Section titled “getDocumentsByKeyword”Description:
| Method | Return values | Description |
|---|---|---|
| getDocumentsByKeyword(String token, String keyword) | List |
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
Section titled “getFoldersByKeyword”Description:
| Method | Return values | Description |
|---|---|---|
| getFoldersByKeyword(String token, String keyword) | List |
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
Section titled “getMailsByKeyword”Description:
| Method | Return values | Description |
|---|---|---|
| getMailsByKeyword(String token, String keyword) | List |
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
Section titled “getRecordsByKeyword”Description:
| Method | Return values | Description |
|---|---|---|
| getRecordsByKeyword(String token, String keyword) | List |
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
Section titled “getDocumentsByPropertyValue”Description:
| Method | Return values | Description |
|---|---|---|
| getDocumentsByPropertyValue(String token, String group, String property, String value) | List |
Retrieves a list of all documents related to 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
Section titled “getFoldersByPropertyValue”Description:
| Method | Return values | Description |
|---|---|---|
| getFoldersByPropertyValue(String token, String group, String property, String value) | List |
Retrieves a list of all folders related to 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
Section titled “getMailsByPropertyValue”Description:
| Method | Return values | Description |
|---|---|---|
| getMailsByPropertyValue(String token, String group, String property, String value) | List |
Retrieves a list of all mails related to 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
Section titled “getRecordsByPropertyValue”Description:
| Method | Return values | Description |
|---|---|---|
| getRecordsByPropertyValue(String token, String group, String property, String value) | List |
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
Section titled “findMailPaginated”Description:
| Method | Return values | Description |
|---|---|---|
| findMailPaginated(String token, Map<String, String> filter, String sortField, boolean sortReverse, int type, int offset, int limit) |
ResultSet | Returns a list of paginated mail results filtered by the values of the parameters. |
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
Section titled “csvExport”Description:
| Method | Return values | Description |
|---|---|---|
| csvExport(String token, String lang, QueryParams params, List |
InputStream | Exports a list of results as a CSV file filtered by the values of the queryParams parameter. Returns the CSV data as an InputStream. |
Example:
package com.openkm;
import java.io.InputStream;import java.util.Arrays;import java.util.List;
import com.openkm.api.OKMSearch;import com.openkm.bean.Ref;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 params = new QueryParams(); params.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER); params.setName("test*");
List<String> propertyGroups = Arrays.asList("okg:consulting"); Ref<String> fileName = new Ref<>(); InputStream is = okmSearch.csvExport(null, "en", params, propertyGroups, false, fileName); System.out.println("File name: " + fileName.get()); } catch (Exception e) { e.printStackTrace(); } }}