OKMSearch
Basics
Section titled “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: - QueryParams.DOCUMENT - QueryParams.FOLDER - QueryParams.MAIL - QueryParams.RECORD By default the value is set to QueryParams.DOCUMENT. For searching documents and folders use value: <br>(QueryParams.DOCUMENT | QueryParams.FOLDER) <br> |
Restricts the search to a node types. |
| author | String | No. | 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 |
Yes. | Filters by keywords. | |
| categories | Set |
No. | Values should be a category UUID, not use 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 is used by default “/okm:root” node. 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 field. |
| mailTo | Yes. | Only apply to mail nodes. | Filters by mail to 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: 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 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: 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 character “;” is used as separator. |
Filters by metadata group values. |
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 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
Section titled “Methods”findByContent
Section titled “findByContent”Description:
| Method | Return values | Description |
|---|---|---|
| findByContent(String content) | List |
Returns a list of results filtered by the value of the content parameter. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findByContent(null, "test")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findByName
Section titled “findByName”Description:
| Method | Return values | Description |
|---|---|---|
| findByName(String token, String words) | List |
Returns a list of results filtered by the value of the name parameter. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findByName(null, "test*.html")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findByKeywords
Section titled “findByKeywords”Description:
| Method | Return values | Description |
|---|---|---|
| findByKeywords(String token, Set |
List |
Returns a list of results filtered by the values of the keywords parameter. |
Example:
package com.openkm;
import java.util.Arrays;import java.util.HashSet;import java.util.Set;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { Set<String> keywords = new HashSet<>(Arrays.asList("test")); for (QueryResult qr : OKMSearch.getInstance().findByKeywords(null, keywords)) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}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.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { QueryParams qParams = new QueryParams(); qParams.setDomain(QueryParams.DOCUMENT); qParams.setName("test*.html"); for (QueryResult qr : OKMSearch.getInstance().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.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { QueryParams qParams = new QueryParams(); qParams.setDomain(QueryParams.DOCUMENT); qParams.setName("test*.html"); for (QueryResult qr : OKMSearch.getInstance().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.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { QueryParams qParams = new QueryParams(); qParams.setDomain(QueryParams.DOCUMENT); qParams.setName("test*.html"); ResultSet rs = OKMSearch.getInstance().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
Section titled “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. |
Example:
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;import com.openkm.bean.ResultSet;import com.openkm.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { QueryParams qParams = new QueryParams(); qParams.setDomain(QueryParams.DOCUMENT); qParams.setName("test*.html"); ResultSet rs = OKMSearch.getInstance().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(); } }}findByQuery
Section titled “findByQuery”Description:
| Method | Return values | Description |
|---|---|---|
| List |
ResultSet |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().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) | ResultSet |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findByQuery(null, "text:grial AND name:o*.pdf", "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 |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findByQueryPaginated(null, "text:grial AND name:o*.pdf", 10, 10)) { 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 |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findByQueryPaginated(null, "text:grial AND name:o*.pdf", 10, 10, "com.openkm.plugin.properties.SimpleNodeProperties")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}saveSearch
Section titled “saveSearch”Description:
| Method | Return values | Description |
|---|---|---|
| saveSearch(String token, QueryParams params) | Long | Saves a search parameters. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { QueryParams qParams = new QueryParams(); qParams.setDomain(QueryParams.DOCUMENT); qParams.setName("test*.html"); // Save the search to be used later qParams.setQueryName("sample search"); OKMSearch.getInstance().saveSearch(null, qParams); } catch (Exception e) { e.printStackTrace(); } }}updateSearch
Section titled “updateSearch”Description:
| Method | Return values | Description |
|---|---|---|
| updateSearch(String token, QueryParams params) | void | Saves a search parameters. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { for (QueryParams qParams : OKMSearch.getInstance().getAllSearchs(null)) { if (qParams.getQueryName().equals("sample search")) { // Change some value. qParams.setName("admin*.html"); OKMSearch.getInstance().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 parameters. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { int qpId = 12; // Some valid search id QueryParams qParams = OKMSearch.getInstance().getSearch(null, qpId); System.out.println(qParams); } catch (Exception e) { e.printStackTrace(); } }}getAllSearchs
Section titled “getAllSearchs”Description:
| Method | Return values | Description |
|---|---|---|
| getAllSearchs(String token) | List |
Retrieves a list of all saved search parameters. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.dao.bean.QueryParams;
public class Test { public static void main(String[] args) { try { for (QueryParams qParams : OKMSearch.getInstance().getAllSearchs(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 parameters. |
package com.openkm;
import com.openkm.api.OKMSearch;
public class Test { public static void main(String[] args) { try { int qpId = 12; // Some valid search id OKMSearch.getInstance().deleteSearch(null, qpId); } catch (Exception e) { e.printStackTrace(); } }}getKeywordMap
Section titled “getKeywordMap”Description:
| Method | Return values | Description |
|---|---|---|
| getKeywordMap(String token, List |
Map<String, Integer> | Returns a map of keywords with its count value filtered by other keywords. |
package com.openkm;
import java.util.ArrayList;import java.util.Arrays;import java.util.Map;
import com.openkm.api.OKMSearch;
public class Test { public static void main(String[] args) { try { // All keywords without filtering System.out.println("Without filtering"); Map<String, Integer> keywords = OKMSearch.getInstance().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.getInstance().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
Section titled “getCategorizedDocuments”Description:
| Method | Return values | Description |
|---|---|---|
| getCategorizedDocuments(String token, String categoryId) | List |
Retrieves a list of all documents related with a category. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { for (Document doc : OKMSearch.getInstance().getCategorizedDocuments(null, "/okm:categories/invoices")) { 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 with a category. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { for (Folder fld : OKMSearch.getInstance().getCategorizedFolders(null, "/okm:categories/invoices")) { 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 with a category. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { for (Mail mail : OKMSearch.getInstance().getCategorizedMails(null, "/okm:categories/invoices")) { 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 with a category. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Record;
public class Test { public static void main(String[] args) { try { for (Record rec : OKMSearch.getInstance().getCategorizedRecords(null, "/okm:categories/invoices")) { 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 with a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { for (Document doc : OKMSearch.getInstance().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 with a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { for (Folder fld : OKMSearch.getInstance().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 with a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { for (Mail mail : OKMSearch.getInstance().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 with a keyword. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Record;
public class Test { public static void main(String[] args) { try { for (Record rec : OKMSearch.getInstance().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 with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Document;
public class Test { public static void main(String[] args) { try { for (Document doc : OKMSearch.getInstance().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 with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Folder;
public class Test { public static void main(String[] args) { try { for (Folder fld : OKMSearch.getInstance().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 with a metadata field value. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.Mail;
public class Test { public static void main(String[] args) { try { for (Mail mail : OKMSearch.getInstance().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;
public class Test { public static void main(String[] args) { try { for (Record rec : OKMSearch.getInstance().getRecordsByPropertyValue(null, "okg:consulting","okp:consulting.name","value")) { System.out.println(rec); } } catch (Exception e) { e.printStackTrace(); } }}findSimpleQuery
Section titled “findSimpleQuery”Description:
| Method | Return values | Description |
|---|---|---|
| findSimpleQuery(String token, String statement) | List |
Returns a list of results filtered by the values of the statement parameter. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;
public class Test { public static void main(String[] args) { try { for (QueryResult qr : OKMSearch.getInstance().findSimpleQuery(null, "name:grial")) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findSimpleQueryPaginated
Section titled “findSimpleQueryPaginated”Description:
| Method | Return values | Description |
|---|---|---|
| findSimpleQueryPaginated(String token, String statement, int offset, int limit) | ResultSet | Returns a list of paginated results filtered by the values of the statement parameter. |
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;import com.openkm.bean.ResultSet;
public class Test { public static void main(String[] args) { try { ResultSet rs = OKMSearch.getInstance().findSimpleQueryPaginated(null, "name:grial", 20, 10); System.out.println("Total results:"+rs.getTotal());
for (QueryResult qr : rs.getResults()) { System.out.println(qr); } } catch (Exception e) { e.printStackTrace(); } }}findMoreLikeThis
Section titled “findMoreLikeThis”Description:
| Method | Return values | Description |
|---|---|---|
| findMoreLikeThis(String token, String uuid, int maxResults) | ResultSet | Returns a list of documents that are considered similar by search engine. |
- The uuid is a document UUID.
- The max value is used to limit the number of results returned.
package com.openkm;
import com.openkm.api.OKMSearch;import com.openkm.bean.QueryResult;import com.openkm.bean.ResultSet;
public class Test { public static void main(String[] args) { try { ResultSet rs = OKMSearch.getInstance().findMoreLikeThis(null, "f123a950-0329-4d62-8328-0ff500fd42db", 100); System.out.println("Total results:"+rs.getTotal());
for (QueryResult qr : rs.getResults()) { System.out.println(qr); } } 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;
public class Test { public static void main(String[] args) { try { Map<String, String> filter = new HashMap<>(); String sortField = "okm:"; int type = OKMSearch.TYPE_MAIL_ALL; ResultSet rs = OKMSearch.getInstance().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(); } }}