Search samples

Basics

Mosts methods use QueryParams. Here there're some tips about using them.

VariablesTypeAllow wildcardsRestrictionsDescription

domain

long

No.

Available values:

  • QueryParams.DOCUMENT
  • QueryParams.FOLDER
  • QueryParams.MAIL

By default the value is set to QueryParams.DOCUMENT.

For searching documents and folders use value:

(QueryParams.DOCUMENT | QueryParams.FOLDER) 

Restrict the search to a node types.

author

String

No.

Value must be a valid userId.

Filter by creator user.

name

String

Yes.

 

Filter by node name.

keywords

Set<String>

Yes.

 

Filter by keywords.

categories

Set<String>

No.

Values should be categories UUID, not use path value.

Filter by categories.

content

 

Yes.

 

Filter by binary content.

mimeType

 

No.

Value should be a valid and registered MIME type.

Only can be applied to documents node.

Filter by document MIME type.

path

 

No.

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

Filter by a folder.

lastModifiedFrom

Calendar

No.

 

Filter by nodes created after a date.

lastModifiedTo

Calendar

No.

 

Filter by nodes creater before a date.

mailSubject

String

Yes.

Only apply to mail nodes.

Filter by mail subject field.

mailFrom

String

Yes.

Only apply to mail nodes.

Filter by mail from field.

mailTo

 

Yes.

Only apply to mail nodes.

Filter by mail to field.

properties

Map<String, String>

Yes on almost.

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

The map of the properties is composed of pairs:

('metadata_field_name','metada_field_value")

For example:

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 range of dates you must set both values ( from and to ), otherwise the filter will be ignored from 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.

Filter by metadata group values.

The search operation is done only by AND logic.

Wildcard examples:

VariableExampleDescription

name

test*.html

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

name

test?.html

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

name

?test*

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

Methods

findByContent

Description:

MethodReturn valuesDescription

findByContent(String content)

List<QueryResult>

Returns a list of results filtered by the value of the content parameter.

The method only search among all documents, it not takes in consideration any other kind of nodes.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8180/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (QueryResult qr : ws.findByContent("test")) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

findByName

Description:

MethodReturn valuesDescription

findByName(String name)

List<QueryResult>

Returns a list of results filtered by the value of the name parameter.

The method only searches among all documents, it does not takes in consideration any other kind of nodes.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8180/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (QueryResult qr : ws.findByName("test*.html")) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

findByKeywords

Description:

MethodReturn valuesDescription

findByKeywords(List<String> keywords)

List<QueryResult>

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

The method only searches among all documents, it does not takes in consideration any other kind of nodes.

Example:

package com.openkm;

import java.util.Arrays;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (QueryResult qr : ws.findByKeywords(Arrays.asList("test"))) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

find

Description:

MethodReturn valuesDescription

find(QueryParams queryParams)

List<QueryResult>

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             QueryParams qParams = new QueryParams();             qParams.setDomain(QueryParams.DOCUMENT);             qParams.setName("test*.html");             
            for (QueryResult qr : ws.find(qParams)) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(QueryParams queryParams, int offset, int limit)

ResultSet

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

The parameter "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" says to skip that many results before the beginning to return results.

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

  • limit=10
  • offset=0

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

  • limit=10
  • offset=10

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             QueryParams qParams = new QueryParams();             qParams.setDomain(QueryParams.DOCUMENT);             qParams.setName("test*.html");             ResultSet rs = ws.findPaginated(qParams, 20, 10);             System.out.println("Total results:"+rs.getTotal());             
            for (QueryResult qr : rs.getResults()) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

findSimpleQueryPaginated

Description:

MethodReturn valuesDescription

findSimpleQueryPaginated(String statement, int offset, int limit)

ResultSet

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

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

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

More information about Lucene sintaxis at Lucene query syntax.

The parameter "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" says to skip that many results before the beginning to return results.

For example if your query have 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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             ResultSet rs = ws.findSimpleQueryPaginated("name:grial", 20, 10);             System.out.println("Total results:"+rs.getTotal());             
            for (QueryResult qr : rs.getResults()) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

findMoreLikeThis

Description:

MethodReturn valuesDescription

findMoreLikeThis(String uuid, int max)

ResultSet

Returns a list of documents that are considered similar by the search engine.

The uuid is a document UUID.

The max value is used to limit the number of results returned.

The method can only be used with documents.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             ResultSet rs = ws.findMoreLikeThis("f123a950-0329-4d62-8328-0ff500fd42db", 100);             System.out.println("Total results:"+rs.getTotal());             
            for (QueryResult qr : rs.getResults()) {                 System.out.println(qr);             } } catch (Exception e) { e.printStackTrace(); } } }

getKeywordMap

Description:

MethodReturn valuesDescription

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

 

Example:

package com.openkm;

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

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8180/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             // All keywords without filtering             System.out.println("Without filtering");             Map<String, Integer> keywords = ws.getKeywordMap(new ArrayList<String>());
            for (String key : keywords.keySet()) {                 System.out.println(key + " is used :" + keywords.get(key) );             }
                         // Keywords filtered             System.out.println("Filtering");             keywords = ws.getKeywordMap(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 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.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8180/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (Document doc : ws.getCategorizedDocuments("/okm:categories/invoices")) {                 System.out.println(doc);             } } catch (Exception e) { e.printStackTrace(); } } }

findByQuery

Description:

MethodReturn valuesDescription

findByQuery(String query)

List<QueryResult>

Returns a list of results filtered by the query parameter.

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 java.util.List;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;

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 {
            List<QueryResult> results = ws.findByQuery("keyword:test AND name:t*.pdf");            

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

findByQueryPaginated

Description:

MethodReturn valuesDescription

findByQueryPaginated(String query, int offset, int limit)

ResultSet

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

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.

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.QueryResult;
import com.openkm.sdk4j.bean.ResultSet;

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 {
            ResultSet rs = ws.findByQueryPaginated("text:grial AND name:t*.pdf", 0, 10);
            System.out.println("Total results:" + rs.getTotal());

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