CODE STYLE class.solr.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 13:23:16 -04:00
parent f11a2fdd93
commit afa04ae6a8

View File

@@ -1,6 +1,6 @@
<?php <?php
/** /**
*
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2012 Colosa Inc.23 * Copyright (C) 2004 - 2012 Colosa Inc.23
* *
@@ -19,12 +19,11 @@
* *
* For more information, contact Colosa Inc, 5304 Ventura Drive, * For more information, contact Colosa Inc, 5304 Ventura Drive,
* Delray Beach, FL, 33484, USA, or email info@colosa.com. * Delray Beach, FL, 33484, USA, or email info@colosa.com.
*
*/ */
/** /**
* Interface to the Solr Search server * Interface to the Solr Search server
*
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* *
*/ */
@@ -34,7 +33,7 @@ class BpmnEngine_SearchIndexAccess_Solr
private $_solrIsEnabled = false; private $_solrIsEnabled = false;
private $_solrHost = ""; private $_solrHost = "";
public function __construct($solrIsEnabled = false, $solrHost = "") public function __construct ($solrIsEnabled = false, $solrHost = "")
{ {
// use the parameters to initialize class // use the parameters to initialize class
$this->_solrIsEnabled = $solrIsEnabled; $this->_solrIsEnabled = $solrIsEnabled;
@@ -49,10 +48,11 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return bool * @return bool
*/ */
public function isEnabled() public function isEnabled ()
{ {
// verify solr server response // verify solr server response
return $this->_solrIsEnabled; return $this->_solrIsEnabled;
} }
@@ -62,46 +62,47 @@ class BpmnEngine_SearchIndexAccess_Solr
* @rest = false * @rest = false
* @background = false * @background = false
* *
* @param * @param workspace: workspace name
* workspace: workspace name
* @return total * @return total
*/ */
public function getNumberDocuments($workspace) public function getNumberDocuments ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
// get total number of documents in registry // get total number of documents in registry
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=*:*"; $solrIntruct .= "/select/?q=*:*";
$solrIntruct .= self::SOLR_VERSION; $solrIntruct .= self::SOLR_VERSION;
$solrIntruct .= "&start=0&rows=0&echoParams=none&wt=json"; $solrIntruct .= "&start=0&rows=0&echoParams=none&wt=json";
$handlerTotal = curl_init ($solrIntruct); $handlerTotal = curl_init( $solrIntruct );
curl_setopt ($handlerTotal, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handlerTotal, CURLOPT_RETURNTRANSFER, true );
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handlerTotal, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handlerTotal, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handlerTotal, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handlerTotal, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handlerTotal, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handlerTotal, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handlerTotal, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handlerTotal, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$responseTotal = curl_exec ($handlerTotal); $responseTotal = curl_exec( $handlerTotal );
curl_close ($handlerTotal); curl_close( $handlerTotal );
// verify the result of solr // verify the result of solr
$responseSolrTotal = G::json_decode ($responseTotal); $responseSolrTotal = G::json_decode( $responseTotal );
if ($responseSolrTotal->responseHeader->status != 0) { if ($responseSolrTotal->responseHeader->status != 0) {
throw new Exception ("Error returning the total number of documents in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error returning the total number of documents in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
$numTotalDocs = $responseSolrTotal->response->numFound; $numTotalDocs = $responseSolrTotal->response->numFound;
return $numTotalDocs; return $numTotalDocs;
@@ -115,7 +116,7 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function executeQuery($solrRequestData) public function executeQuery ($solrRequestData)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
@@ -124,32 +125,32 @@ class BpmnEngine_SearchIndexAccess_Solr
$workspace = $solrRequestData->workspace; $workspace = $solrRequestData->workspace;
// format request // format request
$query = empty ($solrRequestData->searchText) ? '*:*' : $solrRequestData->searchText; $query = empty( $solrRequestData->searchText ) ? '*:*' : $solrRequestData->searchText;
$query = rawurlencode ($query); $query = rawurlencode( $query );
$start = '&start=' . $solrRequestData->startAfter; $start = '&start=' . $solrRequestData->startAfter;
$rows = '&rows=' . $solrRequestData->pageSize; $rows = '&rows=' . $solrRequestData->pageSize;
$fieldList = ''; $fieldList = '';
$cols = $solrRequestData->includeCols; $cols = $solrRequestData->includeCols;
if (! empty ($cols)) { if (! empty( $cols )) {
$fieldList = "&fl=" . implode (",", $cols); $fieldList = "&fl=" . implode( ",", $cols );
} }
$sort = ''; $sort = '';
if ($solrRequestData->numSortingCols > 0) { if ($solrRequestData->numSortingCols > 0) {
$sort = '&sort='; $sort = '&sort=';
for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) {
$sort .= $solrRequestData->sortCols [$i] . "%20" . $solrRequestData->sortDir [$i] . ","; $sort .= $solrRequestData->sortCols[$i] . "%20" . $solrRequestData->sortDir[$i] . ",";
} }
$sort = substr_replace ($sort, "", - 1); $sort = substr_replace( $sort, "", - 1 );
} }
$resultFormat = empty ($solrRequestData->resultFormat) ? '' : '&wt=' . $solrRequestData->resultFormat; $resultFormat = empty( $solrRequestData->resultFormat ) ? '' : '&wt=' . $solrRequestData->resultFormat;
$filters = ''; $filters = '';
$aFilters = explode (',', $solrRequestData->filterText); $aFilters = explode( ',', $solrRequestData->filterText );
foreach ($aFilters as $value) { foreach ($aFilters as $value) {
$filters .= '&fq=' . urlencode ($value); $filters .= '&fq=' . urlencode( $value );
} }
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=$query"; $solrIntruct .= "/select/?q=$query";
$solrIntruct .= "&echoParams=none"; $solrIntruct .= "&echoParams=none";
@@ -162,29 +163,30 @@ class BpmnEngine_SearchIndexAccess_Solr
$solrIntruct .= $resultFormat; $solrIntruct .= $resultFormat;
// send query // send query
// search the cases in base to datatable parameters // search the cases in base to datatable parameters
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
// decode // decode
$responseSolr = G::json_decode ($response); $responseSolr = G::json_decode( $response );
if ($responseSolr->responseHeader->status != 0) { if ($responseSolr->responseHeader->status != 0) {
throw new Exception ("Error executing query to Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error executing query to Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
return $responseSolr; return $responseSolr;
@@ -198,43 +200,44 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function updateDocument($solrUpdateDocument) public function updateDocument ($solrUpdateDocument)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $solrUpdateDocument->workspace; $solrIntruct .= $solrUpdateDocument->workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error updating document in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error updating document in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
@@ -246,43 +249,44 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function commitChanges($workspace) public function commitChanges ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, "<commit/>" ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, "<commit/>"); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error commiting changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error commiting changes in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
@@ -294,44 +298,45 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function rollbackChanges($workspace) public function rollbackChanges ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, "<rollback/>" ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, "<rollback/>"); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error rolling back changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error rolling back changes in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
@@ -343,88 +348,89 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function optimizeChanges($workspace) public function optimizeChanges ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, "<optimize/>" ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, "<optimize/>"); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error optimizing changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error optimizing changes in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
/** /**
* Return the list of the stored fields in Solr * Return the list of the stored fields in Solr
* *
* @param string $workspace * @param string $workspace Solr instance name
* Solr instance name
* @throws Exception * @throws Exception
* @return void mixed of field names * @return void mixed of field names
*/ */
public function getListIndexedStoredFields($workspace) public function getListIndexedStoredFields ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/admin/luke?numTerms=0&wt=json"; $solrIntruct .= "/admin/luke?numTerms=0&wt=json";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
// decode // decode
$responseSolr = G::json_decode ($response); $responseSolr = G::json_decode( $response );
if ($responseSolr->responseHeader->status != 0) { if ($responseSolr->responseHeader->status != 0) {
throw new Exception ("Error getting index fields in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error getting index fields in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
return $responseSolr; return $responseSolr;
} }
@@ -437,46 +443,48 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function deleteAllDocuments($workspace) public function deleteAllDocuments ($workspace)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
// $registry = Zend_Registry::getInstance(); // $registry = Zend_Registry::getInstance();
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, "<delete><query>*:*</query></delete>" ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, "<delete><query>*:*</query></delete>"); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error deleting all documents in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error deleting all documents in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
@@ -488,46 +496,48 @@ class BpmnEngine_SearchIndexAccess_Solr
* *
* @return solr response * @return solr response
*/ */
public function deleteDocument($workspace, $idQuery) public function deleteDocument ($workspace, $idQuery)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
// $registry = Zend_Registry::getInstance(); // $registry = Zend_Registry::getInstance();
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml'
'Content-type:application/xml' ) ); // -H
)); // -H curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary
curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt( $handler, CURLOPT_POSTFIELDS, "<delete><query>" . $idQuery . "</query></delete>" ); // data
curl_setopt ($handler, CURLOPT_POSTFIELDS, "<delete><query>" . $idQuery . "</query></delete>"); // data
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
$swOk = strpos ($response, '<int name="status">0</int>'); $swOk = strpos( $response, '<int name="status">0</int>' );
if (! $swOk) { if (! $swOk) {
throw new Exception ("Error deleting document in Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error deleting document in Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
} }
@@ -537,7 +547,7 @@ class BpmnEngine_SearchIndexAccess_Solr
* @param Entity_FacetRequest $facetRequestEntity * @param Entity_FacetRequest $facetRequestEntity
* @return solr response: list of facets array * @return solr response: list of facets array
*/ */
public function getFacetsList($facetRequest) public function getFacetsList ($facetRequest)
{ {
if (! $this->_solrIsEnabled) if (! $this->_solrIsEnabled)
return; return;
@@ -547,8 +557,8 @@ class BpmnEngine_SearchIndexAccess_Solr
$workspace = $facetRequest->workspace; $workspace = $facetRequest->workspace;
// format request // format request
$query = empty ($facetRequest->searchText) ? '*:*' : $facetRequest->searchText; $query = empty( $facetRequest->searchText ) ? '*:*' : $facetRequest->searchText;
$query = rawurlencode ($query); $query = rawurlencode( $query );
$start = '&start=0'; $start = '&start=0';
$rows = '&rows=0'; $rows = '&rows=0';
$facets = '&facet=on&facet.mincount=1&facet.limit=20'; // enable facet and $facets = '&facet=on&facet.mincount=1&facet.limit=20'; // enable facet and
@@ -561,7 +571,7 @@ class BpmnEngine_SearchIndexAccess_Solr
foreach ($facetRequest->facetQueries as $value) { foreach ($facetRequest->facetQueries as $value) {
$facets .= '&facet.query=' . $value; $facets .= '&facet.query=' . $value;
} }
if (! empty ($facetRequest->facetDates)) { if (! empty( $facetRequest->facetDates )) {
foreach ($facetRequest->facetDates as $value) { foreach ($facetRequest->facetDates as $value) {
$facets .= '&facet.date=' . $value; $facets .= '&facet.date=' . $value;
} }
@@ -575,9 +585,10 @@ class BpmnEngine_SearchIndexAccess_Solr
} }
// echo "<pre>"; // echo "<pre>";
$resultFormat = '&wt=json'; $resultFormat = '&wt=json';
$solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=$query"; $solrIntruct .= "/select/?q=$query";
$solrIntruct .= "&echoParams=none"; $solrIntruct .= "&echoParams=none";
@@ -590,29 +601,30 @@ class BpmnEngine_SearchIndexAccess_Solr
// send query // send query
// search the cases in base to datatable parameters // search the cases in base to datatable parameters
$handler = curl_init ($solrIntruct); $handler = curl_init( $solrIntruct );
curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
//Apply proxy settings //Apply proxy settings
$sysConf = System::getSystemConfiguration(); $sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') { if ($sysConf['proxy_host'] != '') {
curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
if ($sysConf['proxy_port'] != '') { if ($sysConf['proxy_port'] != '') {
curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
} }
if ($sysConf['proxy_user'] != '') { if ($sysConf['proxy_user'] != '') {
curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
) );
} }
$response = curl_exec ($handler); $response = curl_exec( $handler );
curl_close ($handler); curl_close( $handler );
// decode // decode
$responseSolr = G::json_decode ($response); $responseSolr = G::json_decode( $response );
if ($responseSolr->responseHeader->status != 0) { if ($responseSolr->responseHeader->status != 0) {
throw new Exception ("Error getting faceted list from Solr." . $solrIntruct . " response error: " . $response . "\n"); throw new Exception( "Error getting faceted list from Solr." . $solrIntruct . " response error: " . $response . "\n" );
} }
return $responseSolr; return $responseSolr;