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 a node types. |
author |
String |
No. |
Value must be a valid userId. |
Filters by creator user. |
name |
String |
Yes. |
|
Filters by node 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. |
Value should be a valid and registered MIME type. Only can be applied to documents node. |
Filters by document MIME type. | |
path |
No. |
When empty is used by default "/okm:root" node. Value should be a valid path, not use a UUID value. |
Filters 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. |
|
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 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 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
findByContent
Description:
Method | Return values | Description |
---|---|---|
findByContent(String content) |
List<QueryResult> |
Returns a list of results filtered by the value of the content parameter. |
The method only searches among all documents, it does not take in consideration any other kind of nodes. |
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
Description:
Method | Return values | Description |
---|---|---|
findByName(String token, String words) |
List<QueryResult> |
Returns a list of results filtered by the value of the name parameter. |
The method only searches among all documents, it does not take in consideration any other kind of nodes. |
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
Description:
Method | Return values | Description |
---|---|---|
findByKeywords(String token, Set<String> words) |
List<QueryResult> |
Returns a list of results filtered by the values of the keywords parameter. |
The method only searches among all documents, it does not take in consideration any other kind of nodes. |
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();
}
}
}
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.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();
}
}
}
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:
|
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();
}
}
}
saveSearch
Description:
Method | Return values | Description |
---|---|---|
saveSearch(String token, QueryParams params) |
Long |
Saves a 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.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
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.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
Description:
Method | Return values | Description |
---|---|---|
getSearch(String token, int qpId) |
QueryParams |
Gets saved 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.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
Description:
Method | Return values | Description |
---|---|---|
getAllSearchs(String token) |
List<QueryParams> |
Retrieves a list of all saved 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.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
Description:
Method | Return values | Description |
---|---|---|
deleteSearch(String token, long qpId) |
void |
Deletes a saved 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;
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
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;
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
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;
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
Description:
Method | Return values | Description |
---|---|---|
getCategorizedFolders(String token, String categoryId) |
List<Folder> |
Retrieves a list of all folders 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.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
Description:
Method | Return values | Description |
---|---|---|
getCategorizedMails(String token, String categoryId) |
List<Mail> |
Retrieves a list of all mails 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.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();
}
}
}
getDocumentsByKeyword
Description:
Method | Return values | Description |
---|---|---|
getDocumentsByKeyword(String token, String keyword) |
List<Document> |
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
Description:
Method | Return values | Description |
---|---|---|
getFoldersByKeyword(String token, String keyword) |
List<Folder> |
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
Description:
Method | Return values | Description |
---|---|---|
getMailsByKeyword(String token, String keyword) |
List<Mail> |
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();
}
}
}
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;
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
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;
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
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;
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();
}
}
}
findSimpleQuery
Description:
Method | Return values | Description |
---|---|---|
findSimpleQuery(String token, String statement) |
List<QueryResult> |
Returns a list of results filtered by the values of the statement parameter. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax.
|
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
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. |
The syntax to use in the statement parameter is the pair 'field:value'. For example:
More information about lucene sintaxis at Lucene query syntax. The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.
For example if your query has 1000 results, but you only want to return the first 10, you should use these values:
Now suppose you want to show the results from 11-20, you should use these values:
|
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
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. The method can only be used with documents. |
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();
}
}
}