From afa04ae6a88b80822e735e92d7e41e48f3a92590 Mon Sep 17 00:00:00 2001 From: Fernando Ontiveros Date: Tue, 9 Oct 2012 13:23:16 -0400 Subject: [PATCH] CODE STYLE class.solr.php --- workflow/engine/classes/class.solr.php | 1070 ++++++++++++------------ 1 file changed, 541 insertions(+), 529 deletions(-) diff --git a/workflow/engine/classes/class.solr.php b/workflow/engine/classes/class.solr.php index 52061bad4..6aa025006 100644 --- a/workflow/engine/classes/class.solr.php +++ b/workflow/engine/classes/class.solr.php @@ -1,6 +1,6 @@ _solrIsEnabled = $solrIsEnabled; - $this->_solrHost = $solrHost; - } - - /** - * Verify if the Solr service is available - * @gearman = false - * @rest = false - * @background = false - * - * @return bool - */ - public function isEnabled() - { - // verify solr server response - - return $this->_solrIsEnabled; - } - - /** - * Returns the total number of indexed documents - * @gearman = false - * @rest = false - * @background = false - * - * @param - * workspace: workspace name - * @return total - */ - public function getNumberDocuments($workspace) - { - if (! $this->_solrIsEnabled) - return; - // get configuration information in base to workspace parameter - - // get total number of documents in registry - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/select/?q=*:*"; - $solrIntruct .= self::SOLR_VERSION; - $solrIntruct .= "&start=0&rows=0&echoParams=none&wt=json"; - - $handlerTotal = curl_init ($solrIntruct); - curl_setopt ($handlerTotal, CURLOPT_RETURNTRANSFER, true); - - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handlerTotal, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handlerTotal, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handlerTotal, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handlerTotal, CURLOPT_HTTPHEADER, array('Expect:')); + public function __construct ($solrIsEnabled = false, $solrHost = "") + { + // use the parameters to initialize class + $this->_solrIsEnabled = $solrIsEnabled; + $this->_solrHost = $solrHost; } - $responseTotal = curl_exec ($handlerTotal); - curl_close ($handlerTotal); + /** + * Verify if the Solr service is available + * @gearman = false + * @rest = false + * @background = false + * + * @return bool + */ + public function isEnabled () + { + // verify solr server response - // verify the result of solr - $responseSolrTotal = G::json_decode ($responseTotal); - if ($responseSolrTotal->responseHeader->status != 0) { - throw new Exception ("Error returning the total number of documents in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - $numTotalDocs = $responseSolrTotal->response->numFound; - return $numTotalDocs; - } - /** - * Execute a query in base to Requested data - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function executeQuery($solrRequestData) - { - if (! $this->_solrIsEnabled) - return; - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $workspace = $solrRequestData->workspace; - - // format request - $query = empty ($solrRequestData->searchText) ? '*:*' : $solrRequestData->searchText; - $query = rawurlencode ($query); - $start = '&start=' . $solrRequestData->startAfter; - $rows = '&rows=' . $solrRequestData->pageSize; - $fieldList = ''; - $cols = $solrRequestData->includeCols; - if (! empty ($cols)) { - $fieldList = "&fl=" . implode (",", $cols); - } - $sort = ''; - if ($solrRequestData->numSortingCols > 0) { - $sort = '&sort='; - for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { - $sort .= $solrRequestData->sortCols [$i] . "%20" . $solrRequestData->sortDir [$i] . ","; - } - - $sort = substr_replace ($sort, "", - 1); - } - $resultFormat = empty ($solrRequestData->resultFormat) ? '' : '&wt=' . $solrRequestData->resultFormat; - $filters = ''; - $aFilters = explode (',', $solrRequestData->filterText); - foreach ($aFilters as $value) { - $filters .= '&fq=' . urlencode ($value); + return $this->_solrIsEnabled; } - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/select/?q=$query"; - $solrIntruct .= "&echoParams=none"; - $solrIntruct .= self::SOLR_VERSION; - $solrIntruct .= $start; - $solrIntruct .= $rows; - $solrIntruct .= $fieldList; - $solrIntruct .= $sort; - $solrIntruct .= $filters; - $solrIntruct .= $resultFormat; - // send query - // search the cases in base to datatable parameters - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + /** + * Returns the total number of indexed documents + * @gearman = false + * @rest = false + * @background = false + * + * @param workspace: workspace name + * @return total + */ + public function getNumberDocuments ($workspace) + { + if (! $this->_solrIsEnabled) + return; + // get configuration information in base to workspace parameter - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + + // get total number of documents in registry + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/select/?q=*:*"; + $solrIntruct .= self::SOLR_VERSION; + $solrIntruct .= "&start=0&rows=0&echoParams=none&wt=json"; + + $handlerTotal = curl_init( $solrIntruct ); + curl_setopt( $handlerTotal, CURLOPT_RETURNTRANSFER, true ); + + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handlerTotal, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handlerTotal, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handlerTotal, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handlerTotal, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } + + $responseTotal = curl_exec( $handlerTotal ); + curl_close( $handlerTotal ); + + // verify the result of solr + $responseSolrTotal = G::json_decode( $responseTotal ); + if ($responseSolrTotal->responseHeader->status != 0) { + throw new Exception( "Error returning the total number of documents in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } + $numTotalDocs = $responseSolrTotal->response->numFound; + return $numTotalDocs; } - $response = curl_exec ($handler); - curl_close ($handler); + /** + * Execute a query in base to Requested data + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function executeQuery ($solrRequestData) + { + if (! $this->_solrIsEnabled) + return; + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $workspace = $solrRequestData->workspace; - // decode - $responseSolr = G::json_decode ($response); - if ($responseSolr->responseHeader->status != 0) { - throw new Exception ("Error executing query to Solr." . $solrIntruct . " response error: " . $response . "\n"); + // format request + $query = empty( $solrRequestData->searchText ) ? '*:*' : $solrRequestData->searchText; + $query = rawurlencode( $query ); + $start = '&start=' . $solrRequestData->startAfter; + $rows = '&rows=' . $solrRequestData->pageSize; + $fieldList = ''; + $cols = $solrRequestData->includeCols; + if (! empty( $cols )) { + $fieldList = "&fl=" . implode( ",", $cols ); + } + $sort = ''; + if ($solrRequestData->numSortingCols > 0) { + $sort = '&sort='; + for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { + $sort .= $solrRequestData->sortCols[$i] . "%20" . $solrRequestData->sortDir[$i] . ","; + } + + $sort = substr_replace( $sort, "", - 1 ); + } + $resultFormat = empty( $solrRequestData->resultFormat ) ? '' : '&wt=' . $solrRequestData->resultFormat; + $filters = ''; + $aFilters = explode( ',', $solrRequestData->filterText ); + foreach ($aFilters as $value) { + $filters .= '&fq=' . urlencode( $value ); + } + + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/select/?q=$query"; + $solrIntruct .= "&echoParams=none"; + $solrIntruct .= self::SOLR_VERSION; + $solrIntruct .= $start; + $solrIntruct .= $rows; + $solrIntruct .= $fieldList; + $solrIntruct .= $sort; + $solrIntruct .= $filters; + $solrIntruct .= $resultFormat; + // send query + // search the cases in base to datatable parameters + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } + + $response = curl_exec( $handler ); + curl_close( $handler ); + + // decode + $responseSolr = G::json_decode( $response ); + if ($responseSolr->responseHeader->status != 0) { + throw new Exception( "Error executing query to Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } + + return $responseSolr; } - return $responseSolr; - } + /** + * Insert or Update document index + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function updateDocument ($solrUpdateDocument) + { + if (! $this->_solrIsEnabled) + return; + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $solrUpdateDocument->workspace; + $solrIntruct .= "/update"; - /** - * Insert or Update document index - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function updateDocument($solrUpdateDocument) - { - if (! $this->_solrIsEnabled) - return; - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $solrUpdateDocument->workspace; - $solrIntruct .= "/update"; + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document ); // data - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document); // data - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } + + $response = curl_exec( $handler ); + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error updating document in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); - curl_close ($handler); + /** + * Commit the changes since the last commit + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function commitChanges ($workspace) + { + if (! $this->_solrIsEnabled) + return; + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/update"; - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error updating document in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - } + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, "" ); // data - /** - * Commit the changes since the last commit - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function commitChanges($workspace) - { - if (! $this->_solrIsEnabled) - return; - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/update"; - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + $response = curl_exec( $handler ); + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error commiting changes in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); - curl_close ($handler); + /** + * Rollback the changes since the last commit + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function rollbackChanges ($workspace) + { + if (! $this->_solrIsEnabled) + return; - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error commiting changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - } + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/update"; - /** - * Rollback the changes since the last commit - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function rollbackChanges($workspace) - { - if (! $this->_solrIsEnabled) - return; + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, "" ); // data - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/update"; - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + $response = curl_exec( $handler ); + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error rolling back changes in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); - curl_close ($handler); + /** + * Optimize Solr index + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function optimizeChanges ($workspace) + { + if (! $this->_solrIsEnabled) + return; - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error rolling back changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - } + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/update"; - /** - * Optimize Solr index - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function optimizeChanges($workspace) - { - if (! $this->_solrIsEnabled) - return; + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, "" ); // data - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/update"; - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + $response = curl_exec( $handler ); + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error optimizing changes in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); - curl_close ($handler); + /** + * Return the list of the stored fields in Solr + * + * @param string $workspace Solr instance name + * @throws Exception + * @return void mixed of field names + */ + public function getListIndexedStoredFields ($workspace) + { + if (! $this->_solrIsEnabled) + return; - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error optimizing changes in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - } + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/admin/luke?numTerms=0&wt=json"; - /** - * Return the list of the stored fields in Solr - * - * @param string $workspace - * Solr instance name - * @throws Exception - * @return void mixed of field names - */ - public function getListIndexedStoredFields($workspace) - { - if (! $this->_solrIsEnabled) - return; + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/admin/luke?numTerms=0&wt=json"; + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + $response = curl_exec( $handler ); + curl_close( $handler ); + // decode + $responseSolr = G::json_decode( $response ); + if ($responseSolr->responseHeader->status != 0) { + throw new Exception( "Error getting index fields in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } + return $responseSolr; } - $response = curl_exec ($handler); - curl_close ($handler); - // decode - $responseSolr = G::json_decode ($response); - if ($responseSolr->responseHeader->status != 0) { - throw new Exception ("Error getting index fields in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - return $responseSolr; - } + /** + * Delete all documents from index + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function deleteAllDocuments ($workspace) + { + if (! $this->_solrIsEnabled) + return; + // $registry = Zend_Registry::getInstance(); - /** - * Delete all documents from index - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function deleteAllDocuments($workspace) - { - if (! $this->_solrIsEnabled) - return; - // $registry = Zend_Registry::getInstance(); - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/update"; + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/update"; - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, "*:*"); // data + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, "*:*" ); // data - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } + + $response = curl_exec( $handler ); + + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error deleting all documents in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); + /** + * Delete specified documents from index + * @gearman = false + * @rest = false + * @background = false + * + * @return solr response + */ + public function deleteDocument ($workspace, $idQuery) + { + if (! $this->_solrIsEnabled) + return; + // $registry = Zend_Registry::getInstance(); - curl_close ($handler); - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error deleting all documents in Solr." . $solrIntruct . " response error: " . $response . "\n"); - } - } + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/"; + $solrIntruct .= $workspace; + $solrIntruct .= "/update"; - /** - * Delete specified documents from index - * @gearman = false - * @rest = false - * @background = false - * - * @return solr response - */ - public function deleteDocument($workspace, $idQuery) - { - if (! $this->_solrIsEnabled) - return; - // $registry = Zend_Registry::getInstance(); + $handler = curl_init( $solrIntruct ); + curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Content-type:application/xml' + ) ); // -H + curl_setopt( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary + curl_setopt( $handler, CURLOPT_POSTFIELDS, "" . $idQuery . "" ); // data - $solrIntruct = ''; - // get configuration information in base to workspace parameter - $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; - $solrIntruct .= $workspace; - $solrIntruct .= "/update"; - $handler = curl_init ($solrIntruct); - curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); - curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - )); // -H - curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary - curl_setopt ($handler, CURLOPT_POSTFIELDS, "" . $idQuery . ""); // data + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:')); + $response = curl_exec( $handler ); + + curl_close( $handler ); + + $swOk = strpos( $response, '0' ); + if (! $swOk) { + throw new Exception( "Error deleting document in Solr." . $solrIntruct . " response error: " . $response . "\n" ); + } } - $response = curl_exec ($handler); + /** + * Execute a query in base to Request data + * + * @param Entity_FacetRequest $facetRequestEntity + * @return solr response: list of facets array + */ + public function getFacetsList ($facetRequest) + { + if (! $this->_solrIsEnabled) + return; - curl_close ($handler); + $solrIntruct = ''; + // get configuration information in base to workspace parameter + $workspace = $facetRequest->workspace; - $swOk = strpos ($response, '0'); - if (! $swOk) { - throw new Exception ("Error deleting document in Solr." . $solrIntruct . " response error: " . $response . "\n"); + // format request + $query = empty( $facetRequest->searchText ) ? '*:*' : $facetRequest->searchText; + $query = rawurlencode( $query ); + $start = '&start=0'; + $rows = '&rows=0'; + $facets = '&facet=on&facet.mincount=1&facet.limit=20'; // enable facet and + // only return facets + // with minimun one + // instance + foreach ($facetRequest->facetFields as $value) { + $facets .= '&facet.field=' . $value; + } + foreach ($facetRequest->facetQueries as $value) { + $facets .= '&facet.query=' . $value; + } + if (! empty( $facetRequest->facetDates )) { + foreach ($facetRequest->facetDates as $value) { + $facets .= '&facet.date=' . $value; + } + $facets .= '&facet.date.start=' . $facetRequest->facetDatesStart; + $facets .= '&facet.date.end=' . $facetRequest->facetDatesEnd; + $facets .= '&facet.date.gap=' . $facetRequest->facetDateGap; + } + $filters = ''; + foreach ($facetRequest->filters as $value) { + $filters .= '&fq=' . $value; + } + // echo "
";
+
+
+        $resultFormat = '&wt=json';
+
+        $solrIntruct = (substr( $this->_solrHost, - 1 ) == "/") ? $this->_solrHost : $this->_solrHost . "/";
+        $solrIntruct .= $workspace;
+        $solrIntruct .= "/select/?q=$query";
+        $solrIntruct .= "&echoParams=none";
+        $solrIntruct .= self::SOLR_VERSION;
+        $solrIntruct .= $start;
+        $solrIntruct .= $rows;
+        $solrIntruct .= $facets;
+        $solrIntruct .= $filters;
+        $solrIntruct .= $resultFormat;
+
+        // send query
+        // search the cases in base to datatable parameters
+        $handler = curl_init( $solrIntruct );
+        curl_setopt( $handler, CURLOPT_RETURNTRANSFER, true );
+
+        //Apply proxy settings
+        $sysConf = System::getSystemConfiguration();
+        if ($sysConf['proxy_host'] != '') {
+            curl_setopt( $handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') );
+            if ($sysConf['proxy_port'] != '') {
+                curl_setopt( $handler, CURLOPT_PROXYPORT, $sysConf['proxy_port'] );
+            }
+            if ($sysConf['proxy_user'] != '') {
+                curl_setopt( $handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') );
+            }
+            curl_setopt( $handler, CURLOPT_HTTPHEADER, array ('Expect:'
+            ) );
+        }
+
+        $response = curl_exec( $handler );
+        curl_close( $handler );
+
+        // decode
+        $responseSolr = G::json_decode( $response );
+        if ($responseSolr->responseHeader->status != 0) {
+            throw new Exception( "Error getting faceted list from Solr." . $solrIntruct . " response error: " . $response . "\n" );
+        }
+
+        return $responseSolr;
     }
-  }
-
-  /**
-   * Execute a query in base to Request data
-   *
-   * @param Entity_FacetRequest $facetRequestEntity
-   * @return solr response: list of facets array
-   */
-  public function getFacetsList($facetRequest)
-  {
-    if (! $this->_solrIsEnabled)
-      return;
-
-    $solrIntruct = '';
-    // get configuration information in base to workspace parameter
-    $workspace = $facetRequest->workspace;
-
-    // format request
-    $query = empty ($facetRequest->searchText) ? '*:*' : $facetRequest->searchText;
-    $query = rawurlencode ($query);
-    $start = '&start=0';
-    $rows = '&rows=0';
-    $facets = '&facet=on&facet.mincount=1&facet.limit=20'; // enable facet and
-                                                           // only return facets
-                                                           // with minimun one
-                                                           // instance
-    foreach ($facetRequest->facetFields as $value) {
-      $facets .= '&facet.field=' . $value;
-    }
-    foreach ($facetRequest->facetQueries as $value) {
-      $facets .= '&facet.query=' . $value;
-    }
-    if (! empty ($facetRequest->facetDates)) {
-      foreach ($facetRequest->facetDates as $value) {
-        $facets .= '&facet.date=' . $value;
-      }
-      $facets .= '&facet.date.start=' . $facetRequest->facetDatesStart;
-      $facets .= '&facet.date.end=' . $facetRequest->facetDatesEnd;
-      $facets .= '&facet.date.gap=' . $facetRequest->facetDateGap;
-    }
-    $filters = '';
-    foreach ($facetRequest->filters as $value) {
-      $filters .= '&fq=' . $value;
-    }
-    // echo "
";
-
-    $resultFormat = '&wt=json';
-
-    $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
-    $solrIntruct .= $workspace;
-    $solrIntruct .= "/select/?q=$query";
-    $solrIntruct .= "&echoParams=none";
-    $solrIntruct .= self::SOLR_VERSION;
-    $solrIntruct .= $start;
-    $solrIntruct .= $rows;
-    $solrIntruct .= $facets;
-    $solrIntruct .= $filters;
-    $solrIntruct .= $resultFormat;
-
-    // send query
-    // search the cases in base to datatable parameters
-    $handler = curl_init ($solrIntruct);
-    curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true);
-
-    //Apply proxy settings
-    $sysConf = System::getSystemConfiguration();
-    if ($sysConf['proxy_host'] != '') {
-      curl_setopt($handler, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : ''));
-      if ($sysConf['proxy_port'] != '') {
-        curl_setopt($handler, CURLOPT_PROXYPORT, $sysConf['proxy_port']);
-      }
-      if ($sysConf['proxy_user'] != '') {
-        curl_setopt($handler, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : ''));
-      }
-      curl_setopt($handler, CURLOPT_HTTPHEADER, array('Expect:'));
-    }
-
-    $response = curl_exec ($handler);
-    curl_close ($handler);
-
-    // decode
-    $responseSolr = G::json_decode ($response);
-    if ($responseSolr->responseHeader->status != 0) {
-      throw new Exception ("Error getting faceted list from Solr." . $solrIntruct . " response error: " . $response . "\n");
-    }
-
-    return $responseSolr;
-  }
 }