OKMSearch

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:

(QueryParams.DOCUMENT | QueryParams.FOLDER) 

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<String>

Yes.

 

Filters by keywords.

categories

Set<String>

No.

Values should be a category UUID; do not use a path value.

Filters by categories.

content

 

Yes.

 

Filters by binary content.

mimeType

 

No.

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:

Map<String, String> properties = new HashMap();
properties.put("okp:consulting.name", "name value");

Filtering by range of dates:

Calendar to = Calendar.getInstance(); // today
to.set(0, Calendar.HOUR);
to.set(0, Calendar.MINUTE);
to.set(0, Calendar.SECOND);
to.set(0, Calendar.MILLISECOND);
Calendar from = (Calendar) to.clone();
from.add(-3, Calendar.DATE); // three days before
Map<String,String> properties = new HashMap<>();
properties.put("okp:consulting.date", ISO8601.formatBasic(from)+","+ISO8601.formatBasic(to));

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:

<select label="Multiple" name="okp:consulting.multiple" type="multiple">
  <option label="One" value="one"/>
  <option label="Two" value="two"/>
  <option label="Three" value="three" />
</select>

You should do:

properties.put("okp:consulting.multiple", "one;two");

Where "one" and "two" are valid values and the character ";" is used as a separator.

Filters by metadata group values.

The search operation is performed using only AND logic.

Wildcard examples:

Variable Example Description

name

test*.html

Any document that starts with 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

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 - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables 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();
        }
    }
}

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 parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before returning results.

For example if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables 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();
        }
    }
}

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 of the metadata group.

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables 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();
        }
    }
}

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 parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" used to skip that many results before the beginning to return results.

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:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables 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();
        }
    }
}

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:

  • "name:grial" filters the field name by the word "grial".

More information about Lucene syntax 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.

The parameter "propertiesPlugin" must be the canonical class name of the class which implements the NodeProperties interface.

Available sortField values:

name
author
lastModified

The syntax to use in the statement parameter is the pair 'field:value'. For example:

  • "name:grial" filters the field name by the word "grial".

More information about Lucene syntax 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 parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before the beginning to return results.

For example if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

The syntax to use in the statement parameter is the pair 'field:value'. For example:

  • "name:grial" is filtering field name by word grial.

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 "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before the beginning to return results.

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:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables you really need.

The syntax to use in the statement parameter is the pair 'field:value'. For example:

  • "name:grial" is filtering field name by word grial.

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 parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before the beginning to return results.

The parameter "propertiesPlugin" must be a canonical class name of the class which implements the NodeProperties interface.

Available sortField values:

name
author
lastModified

For example if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - the marshalling and unmarshalling process - when you are only interested in a few object variables. If that's your case you can use NodeProperties classes to retrieve only the object variables you really need.

The syntax to use in the statement parameter is the pair 'field:value'. For example:

  • "name:grial" filters the field name by the word "grial".

More information about Lucene syntax 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.

The parameter "limit" and "offset" allows you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before the beginning to return results.

Available sortField values:

name
author
lastModified

For example if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

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:

  • "name:grial" filters the field name by the word "grial".

More information about Lucene syntax 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 search parameters.

Only a saved search created by the same user who's executing the method can be updated.

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 a saved search created by the same user who's executing the method can be updated.

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 searches.

Only a saved search created by the same user who's executing the method can be updated.

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 a saved search created by the same user who's executing the method can be updated.

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:

  • Doc1.txt has keywords "test", "one", "two".
  • Doc2.txt has keywords "test", "one"
  • Doc3.txt has keywords "test", "three".

Results filtered by "test" -> "one", "two", "three".

Results filtered by "one" -> "test", "two".

Results filtered by "two" -> "test", "one".

Results filtered by "three" -> "test".

Results filtered 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 to a category.

The value 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 value 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 value 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 value 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 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

Description:

Method Return values Description

getFoldersByPropertyValue(String token, String group, String property, String value)

List<Folder>

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

Description:

Method Return values Description

getMailsByPropertyValue(String token, String group, String property, String value)

List<Mail>

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

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,
            int offset, int limit)

ResultSet

Returns a list of paginated mail results filtered by the values of the parameters.

Allowed filter key values are:

  • Mail.SENT_DATE
  • Mail.SUBJECT
  • Mail.TO

The send data value format must be:

ISO8601.formatBasic(from)+","+ISO8601.formatBasic(to)

Allowed sortField values are:

  • "okm:" for no sorting.
  • Mail.TYPE
  • Mail.SUBJECT
  • Mail.FROM
  • Mail.SENT_DATE
  • Mail.SIZE
  • Mail.REPLY
  • Mail.TO
  • Mail.CC
  • Mail.BCC
  • Mail.CONTENT

Allowed type values are:

  • OKMSearch.TYPE_MAIL_ALL
  • OKMSearch.TYPE_MAIL_WITHOUT_ATTACHMENT
  • OKMSearch.TYPE_MAIL_WITH_ATTACHMENT

The parameters "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" is used to skip that many results before the start of the returned results.

For example, if your query has 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11 to 20, you should use these values:

  • limit=10
  • offset=10
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

Exports a list of results as a CSV file filtered by the values of the queryParams parameter.

The parameter lang must be ISO 639-1 compliant.

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();
        }
    }
}