OKMSearch

Basics

Almosts all methods use QueryParams. Here there're some tips about how using it.

VariablesTypeAllow wildcardsRestrictionsDescription

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:

(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 name.

keywords

Set<String>

Yes.

 

Filters by keywords.

categories

Set<String>

No.

Values should be a category UUID, not use path value.

Filters by categories.

content

 

Yes.

 

Filters by binary content.

mimeType

 

No.

The value should be a valid and registered MIME type.

Only can be applied to documents node.

Filters by document MIME type.

language

 

No.

The value should be a valid language.

Only can be applied to documents node.

Filters by document language.

folder

 

No.

When empty is used by default "/okm:root" node.

The value should be a valid UUID, not use a path value.

Filters by a folder.

folderRecursive

Boolean

No.

Only has sense to set this variable to true when the variable folder is not empty.

Enables filter recursively by a folder.

lastModifiedFrom

Calendar

No.

 

Filters by nodes created after a date.

lastModifiedTo

Calendar

No.

 

Filters by nodes created before a date.

mailSubject

String

Yes.

Only apply to mail nodes.

Filters by mail subject field.

mailFrom

String

Yes.

Only apply to mail nodes.

Filters by mail from the field.

mailTo

 

Yes.

Only apply to mail nodes.

Filters by mail to the field.

notes

 

Yes.

 

Filters by notes.

properties

Map<String, String>

Yes on almost.

On metadata field values like "date" can not be applied wilcards.

The map of the properties is composed of pairs:

('metadata_field_name','metada_field_value")

For example:

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 from the  OpenKM side.

To filtering 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 character ";" is used as separator.

Filters by metadata group values.

The search operation is done only by AND logic.

Wildcard examples:

VariableExampleDescription

name

test*.html

Any document that starts with characters "test" and ends with characters ".html"

name

test?.html

Any document that starts with the characters "test" followed by a single character and ends with characters ".html"

name

?test*

Any of the documents where the first character doesn't matter but is followed by the characters, "test".

Methods

find

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

find(String token, QueryParams params, String propertiesPlugin)

List<QueryResult>

Returns a list of results filtered by the values of the queryParams parameter.

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

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");

            for (QueryResult qr : okmSearch.find(null, qParams, "com.openkm.plugin.properties.SimpleNodeProperties")) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

find

Description:

MethodReturn valuesDescription

find(String token, QueryParams params, String sortField, boolean sortReverse, String propertiesPlugin)

List<QueryResult>

Returns a list of results filtered by the values of the queryParams parameter.

From version 7.1.27 of OpenKM this method was added

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

Available sortField values:

name
author
lastModified

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");

            for (QueryResult qr : okmSearch.find(null, qParams, "name", true, "com.openkm.plugin.properties.SimpleNodeProperties")) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findPaginated

Description:

MethodReturn valuesDescription

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.

  • 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

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            ResultSet rs = okmSearch.findPaginated(null, qParams, 20, 10);
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(String token, QueryParams params, int offset, int limit, String propertiesPlugin)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

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

  • The parameter "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 the canonical class name of the class which implements the NodeProperties interface.

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

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

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            ResultSet rs = okmSearch.findPaginated(null, qParams, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties");
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

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

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

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            ResultSet rs = okmSearch.findPaginated(null, qParams, "name", true, 20, 10);
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

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

  • The parameter "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 the 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 - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            ResultSet rs = okmSearch.findPaginated(null, qParams, "name", true, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties");
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findWithMetadata

Description:

MethodReturn valuesDescription

findWithMetadata(String token, QueryParams params, String propertiesPlugin, List<String> groups)

List<QueryResult>

Returns a list of results filtered by the values of the queryParams parameter.

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

The parameter "groups" is the name metadata group.

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");

            List<String> groups = new ArrayList<>();
            groups.add("okg:tpl");

            for (QueryResult qr : okmSearch.findWithMetadata(null, qParams, "com.openkm.plugin.properties.SimpleNodeProperties",
                    groups)) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findWithMetadata

Description:

MethodReturn valuesDescription

findWithMetadata(String token, QueryParams params, String sortField, boolean sortReverse, String propertiesPlugin, List<String> groups)

List<QueryResult>

Returns a list of results filtered by the values of the queryParams parameter.

From version 7.1.27 of OpenKM this method was added

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

The parameter "groups" is the name metadata group.

Available sortField values:

name
author
lastModified

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only a few Objects variables. If it's your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");

            List<String> groups = new ArrayList<>();
            groups.add("okg:tpl");

            for (QueryResult qr : okmSearch.findWithMetadata(null, qParams, "name", true, "com.openkm.plugin.properties.SimpleNodeProperties",
                    groups)) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findWithMetadataPaginated

Description:

MethodReturn valuesDescription

findWithMetadataPaginated(String token, QueryParams params, int offset, int limit, String propertiesPlugin, List<String> groups)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

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

  • The parameter "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 - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");

            List<String> groups = new ArrayList<>();
            groups.add("okg:tpl");

            ResultSet rs = okmSearch.findWithMetadataPaginated(null, qParams, 0, 10, "com.openkm.plugin.properties.SimpleNodeProperties", groups);
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findWithMetadataPaginated

Description:

MethodReturn valuesDescription

findWithMetadataPaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin, List<String> groups)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

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

  • The parameter "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.

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.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.bean.ResultSet;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            String sortField = "okm:";
            boolean sortReverse = false;

            List<String> groups = new ArrayList<>();
            groups.add("okg:tpl");

            ResultSet rs = okmSearch.findWithMetadataPaginated(null, qParams, sortField, sortReverse, 20, 10, "com.openkm.plugin.properties.SimpleNodeProperties", groups);
            System.out.println("Total results:" + rs.getTotal());

            for (QueryResult qr : rs.getResults()) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findSimpleNodeBasePaginated

Description:

MethodReturn valuesDescription

findSimpleNodeBasePaginated(String token, QueryParams params, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin)

SimpleNodeBaseResultSet

Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter.

From version 7.1.19 of OpenKM this method was added

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

  • The parameter "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 the 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 - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;
import com.openkm.ws.rest.util.SimpleNodeBase;
import com.openkm.ws.rest.util.SimpleNodeBaseResultSet;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT + QueryParams.FOLDER);
            qParams.setName("test*");
            SimpleNodeBaseResultSet resultSet = okmSearch.findSimpleNodeBasePaginated(null, qParams, "name", true, 0, 10);
            System.out.println("Total results:" + resultSet.getTotal());

            for (SimpleNodeBase simpleNodeBase : resultSet.getResults()) {
                System.out.println(simpleNodeBase);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findByQuery

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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" is filtering field name by word grial.

More information about lucene sintaxis at Lucene query syntax.

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.QueryResult;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (QueryResult qr : okmSearch.findByQuery(null, "text:grial AND name:o*.pdf",
                    "com.openkm.plugin.properties.SimpleNodeProperties")) {
                System.out.println(qr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findByQuery

Description:

MethodReturn valuesDescription

findByQuery(String token, String query, String sortField, boolean sortReverse, String propertiesPlugin)

ResultSet

Returns a list of paginated results filtered by the value of the query parameter.

From version 7.1.27 of OpenKM this method was added

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

Available sortField values:

name
author
lastModified

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.

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:

MethodReturn valuesDescription

findByQueryPaginated(String token, String query, int offset, int limit)

ResultSet

Returns a list of paginated results filtered by the value of the query parameter.

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

  • 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:

MethodReturn valuesDescription

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 - 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" 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:

MethodReturn valuesDescription

findByQueryPaginated(String token, String query, String sortField, boolean sortReverse, int offset, int limit, String propertiesPlugin)

ResultSet

Returns a list of paginated results filtered by the value of the query parameter.

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

  • The parameter "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 - 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" 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", "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:

MethodReturn valuesDescription

findSimpleNodeBaseByQueryPaginated(String token, String query, String sortField, boolean sortReverse, int offset, int limit)

SimpleNodeBaseResultSet

Returns a list of SimpleNodeBase paginated results filtered by the values of the queryParams parameter.

From version 7.1.20 of OpenKM this method was added

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

  • 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" 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.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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

updateSearch(String token, QueryParams params)

void

Saves a search parameters.

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

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (QueryParams qParams : okmSearch.getAllSearches(null)) {
                if (qParams.getQueryName().equals("sample search")) {
                    // Change some value.
                    qParams.setName("admin*.html");
                    okmSearch.updateSearch(null, qParams);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSearch

Description:

MethodReturn valuesDescription

getSearch(String token, int qpId)

QueryParams

Gets saved search.

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

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            int qpId = 1; // Some valid search id
            QueryParams qParams = okmSearch.getSearch(null, qpId);
            System.out.println(qParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAllSearches

Description:

MethodReturn valuesDescription

getAllSearches(String token)

List<QueryParams>

Retrieves a list of all saved search.

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

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.db.bean.QueryParams;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (QueryParams qParams : okmSearch.getAllSearches(null)) {
                System.out.println(qParams);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteSearch

Description:

MethodReturn valuesDescription

deleteSearch(String token, long qpId)

void

Deletes a saved search.

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

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            int qpId = 1; // Some valid search id
            okmSearch.deleteSearch(null, qpId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getKeywordMap

Description:

MethodReturn valuesDescription

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

The results filtering by "test" -> "one", "two", "three".

The results filtering by "one" -> "test", "two".

The results filtering by "two" -> "test", "one".

The results filtering by "three" -> "test".

The results filtering by "one" and "two" -> "test"

package com.openkm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import com.openkm.api.OKMSearch;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            // All keywords without filtering
            System.out.println("Without filtering");
            Map<String, Integer> keywords = okmSearch.getKeywordMap(null, new ArrayList<String>());

            for (String key : keywords.keySet()) {
                System.out.println(key + " is used :" + keywords.get(key));
            }

            // Keywords filtered
            System.out.println("Filtering");
            keywords = okmSearch.getKeywordMap(null, Arrays.asList("test"));

            for (String key : keywords.keySet()) {
                System.out.println(key + " is used :" + keywords.get(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCategorizedDocuments

Description:

MethodReturn valuesDescription

getCategorizedDocuments(String token, String categoryId)

List<Document>

Retrieves a list of all documents related with a category.

The values of the categoryId parameter should be a category folder UUID or path.
package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Document;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Document doc : okmSearch.getCategorizedDocuments(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCategorizedFolders

Description:

MethodReturn valuesDescription

getCategorizedFolders(String token, String categoryId)

List<Folder>

Retrieves a list of all folders related to a category.

The values of the categoryId parameter should be a category folder UUID or path.
package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Folder fld : okmSearch.getCategorizedFolders(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
                System.out.println(fld);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCategorizedMails

Description:

MethodReturn valuesDescription

getCategorizedMails(String token, String categoryId)

List<Mail>

Retrieves a list of all mails related to a category.

The values of the categoryId parameter should be a category folder UUID or path.
package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Mail;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Mail mail : okmSearch.getCategorizedMails(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
                System.out.println(mail);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCategorizedRecords

Description:

MethodReturn valuesDescription

getCategorizedRecords(String token, String categoryId)

List<Record>

Retrieves a list of all records related to a category.

The values of the categoryId parameter should be a category folder UUID or path.
package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Record rec : okmSearch.getCategorizedRecords(null, "5cbc35fc-23c0-48f5-a7bc-3cfa1e7be25f")) {
                System.out.println(rec);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDocumentsByKeyword

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

getDocumentsByPropertyValue(String token, String group, String property, String value

List<Document>

Retrieves a list of all documents related with a metadata field value.

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Document;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Document doc : okmSearch.getDocumentsByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getFoldersByPropertyValue

Description:

MethodReturn valuesDescription

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

List<Folder>

Retrieves a list of all folders related with a metadata field value.

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Folder fld : okmSearch.getFoldersByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
                System.out.println(fld);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getMailsByPropertyValue

Description:

MethodReturn valuesDescription

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

List<Mail>

Retrieves a list of all mails related with a metadata field value.

package com.openkm;

import com.openkm.api.OKMSearch;
import com.openkm.bean.Mail;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMSearch okmSearch = ContextWrapper.getContext().getBean(OKMSearch.class);
            for (Mail mail : okmSearch.getMailsByPropertyValue(null, "okg:consulting", "okp:consulting.name", "value")) {
                System.out.println(mail);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRecordsByPropertyValue

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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

Send data value format must be:

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

Allowed sortField values are:

  • "okm:" for a non sorted.
  • 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 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.

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

MethodReturn valuesDescription

csvExport(String lang, QueryParams queryParams, boolean compact, String filename)

InputStream

Export as a csv a list of results filtered by the values of the queryParams parameter.

Method added from OpenKM version 7.1.27.

The parameter lang must be ISO 691-1 compliant.

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