Search samples

Basics

Mosts methods use QueryParams here there're some tips about how using it.

VariablesTypeAllow wildcardsRestrictionsDescription

domain

int

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) 

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.

title

string

Yes.

  Filter by title name.

keywords

array

Yes.

 

Filter by keywords.

categories

array

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.

language

 

No.

Value should be a valid language.

Only can be applied to documents node.

Filter by document language.

folder

 

No.

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

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

Filter by a folder.

folderRecursive

bool

No.

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

Enable filter recursively by a folder.

lastModifiedFrom

date

No.

 

Filter by nodes created after a date.

lastModifiedTo

date

No.

 

Filter by nodes created 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.

notes

 

Yes.

 

Filter by notes.

properties

array

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:

$properties = array();
$properties['okp:consulting.name'] = 'name value';

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 of the documents where the first character doesn't matter, but is followed by the characters, "test".

Methods

findByContent

Description:

MethodReturn valuesDescription

findByContent($content)

array

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

Parameters:
$content
string type

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

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testFindByContent() {
        try {
            $queryResults = $this->ws->findByContent('test*');
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindByContent();
?>

findByName

Description:

MethodReturn valuesDescription

findByName($name)

array

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

Parameters:
$name
string type

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

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testFindByName() {
        try {
            $queryResults = $this->ws->findByName('test');
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindByName();
?>

findByKeywords

Description:

MethodReturn valuesDescription

findByKeywords($keywords)

array

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

Parameters:
$keywords
array type

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

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testFindByKeywords(){
        try {
            $keywords = array();            
            $keywords[] = 'php';
            $queryResults = $this->ws->findByKeywords($keywords);
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindByKeywords();
?>

find

Description:

MethodReturn valuesDescription

find(QueryParams $queryParams)

array

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

Parameters:
$queryParams
QueryParams type

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testFind() {
        try {
            $queryParams = new QueryParams();
            $queryParams->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
            $queryParams->setFolder("398735af-6282-450e-863c-d00390c5bdda");
            $queryParams->setFolderRecursive(true);
            $queryParams->setLastModifiedFrom(20150628000000);
            $queryParams->setLastModifiedTo(date('Ymdhis'));
            $queryResults = $this->ws->find($queryParams);            
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFind();
?>

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(QueryParams $queryParams, $offset, $limit)

ResultSet

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

Parameters:
$queryParams
QueryParams type

$offset int type

$limit int type

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:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testFindPaginated(){
        try {
            $queryParams = new QueryParams();
            $queryParams->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
            $queryParams->setFolder("398735af-6282-450e-863c-d00390c5bdda");
            $queryParams->setFolderRecursive(true);
            $queryParams->setLastModifiedFrom(20150628000000);
            $queryParams->setLastModifiedTo(date('Ymdhis'));
            $resultSet = $this->ws->findPaginated($queryParams,0,10);            
            echo "Total results:" . $resultSet->getTotal();
            foreach ($resultSet->getResults() as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindPaginated();
?>

findSimpleQueryPaginated

Description:

MethodReturn valuesDescription

findSimpleQueryPaginated($statement, $offset, $limit)

ResultSet

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

Parameters:
$statement
string type

$offset int type

$limit int type

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:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testFindSimpleQueryPaginated(){
        try {
            $resultSet = $this->ws->findSimpleQueryPaginated('name:grial',0,10);            
            echo "Total results:" . $resultSet->getTotal();
            foreach ($resultSet->getResults() as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
    
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindSimpleQueryPaginated();
?>

findMoreLikeThis

Description:

MethodReturn valuesDescription

findMoreLikeThis(String uuid, int max)

ResultSet

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

Parameters:
$statement
string type is the uuid of the Document

$offset int type is the max value is used to limit the number of results returned.

The method can only be used with documents.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testFindMoreLikeThis(){
        try {
            $resultSet = $this->ws->findMoreLikeThis("96c44de6-1d0d-45fb-b380-4984f46bbeb3", 100);           
            echo "Total results:" . $resultSet->getTotal();
            foreach ($resultSet->getResults() as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
    
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testFindMoreLikeThis();
?>

getKeywordMap

Description:

MethodReturn valuesDescription

getKeywordMap($filter)

array

Returns a array of the KeywordMap with its count value filtered by other keywords.

Parameters:
$filter
array type is the uuid of the Document

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:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
    
    public function testKeywordMap(){
        try {
            // All keywords without filtering
            echo 'Without filtering';
            $keywordMaps = $this->ws->getKeywordMap();
            foreach ($keywordMaps as $keywordMap) {
                var_dump($keywordMap);
            }
            // Keywords filtered
            echo 'Filtering';
            $filter = array('test','php');            
            $keywordMaps = $this->ws->getKeywordMap($filter);
            foreach ($keywordMaps as $keywordMap) {
                var_dump($keywordMap);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
    
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testKeywordMap();
?>

getCategorizedDocuments

Description:

MethodReturn valuesDescription

getCategorizedDocuments(String categoryId)

List<Document>

Retrieves a list of all documents related with a category.

Parameters:
$categoryId
string type is the uuid or path of the Category

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetCategorizedDocuments(){
        try {
            $documents = $this->ws->getCategorizedDocuments('abd631c5-93b8-4265-98f2-152c91f43a9c');
            foreach ($documents as $document) {
                var_dump($document);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
    
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testGetCategorizedDocuments();
?>

saveSearch

MethodReturn valuesDescription

saveSearch(QueryParams $params)

int

Saves a search parameters and returns the id of the saved search

Parameters:
$params
QueryParams type is the variable queryName of the parameter params, should have to be initialized.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }
        
    public function testSaveSearch() {
        try {
            $params = new QueryParams();
            $params->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
            $params->setName('test*');
            $params->setFolder("398735af-6282-450e-863c-d00390c5bdda");
            $params->setFolderRecursive(true);
            $params->setLastModifiedFrom(20150628000000);
            $params->setLastModifiedTo(date('Ymdhis'));
            $queryResults = $this->ws->find($params);            
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
            $params->setQueryName('sample search');
            var_dump($this->ws->saveSearch($params));            
        } catch (Exception $e) {
            var_dump($e);
        }
    }
    
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testSaveSearch();
?>

updateSearch

Description:

MethodReturn valuesDescription

updateSearch(QueryParams $params)

void

Updates a previously saved search parameters.

Parameters:
$params
QueryParams type

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

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testUpdateSearch() {
        try {
            $qpId = 1; // Some valid search id
            $params = $this->ws->getSearch($qpId);
            $params->setName('test*.pdf');
            $this->ws->updateSearch($params);
            echo 'update search';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testUpdateSearch();
?>

getSearch

Description:

MethodReturn valuesDescription

getSearch($qpId)

QueryParams

Gets a saved search parameters.

Parameters:
$qpId
int type is the id of the saved search

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

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetSearch() {
        try {
            $qpId = 2; // Some valid search id
            $params = $this->ws->getSearch($qpId);
            var_dump($params);
        } catch (Exception $e) {
            var_dump($e);
        }
    }
}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testGetSearch();
?>

getAllSearchs

Description:

MethodReturn valuesDescription

getAllSearchs()

List<QueryParams>

Retrieve a list of all saved search parameters.

Only will be retrieved the list of the saved searches created by the same user who's executing the method.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testGetAllSearchs() {
        try {
            foreach ($this->ws->getAllSearchs() as $params) {
                var_dump($params);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testGetAllSearchs();
?>

deleteSearch

Description:

MethodReturn valuesDescription

deleteSearch(int qpId)

void

Deletes a saved search parameters.

Parameters:
$qpId
int type is the id of the saved search

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

Example:

<?php

include '../src/openkm/OpenKM.php';

ini_set('display_errors', true);
error_reporting(E_ALL);

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;

class ExampleSearch {

    const HOST = "http://localhost:8080/OpenKM/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
    }

    public function testDeleteSearch() {
        try {
            $qpId = 2; // Some valid search id
            $this->ws->deleteSearch($qpId);
            echo 'delete search';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleSearch = new ExampleSearch();
$exampleSearch->testGetAllSearchs();
?>