CODE STYLE class.searchIndex.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 13:21:57 -04:00
parent 5919afd930
commit d73f690e1d

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,10 +19,8 @@
* *
* 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.
*
*/ */
/** /**
* Class used as interface to have access to the search index services * Class used as interface to have access to the search index services
* *
@@ -34,7 +32,7 @@ class BpmnEngine_Services_SearchIndex
private $_solrIsEnabled = false; private $_solrIsEnabled = false;
private $_solrHost = ""; private $_solrHost = "";
function __construct($solrIsEnabled = false, $solrHost = "") public function __construct ($solrIsEnabled = false, $solrHost = "")
{ {
// check if Zend Library is available // check if Zend Library is available
// if(class_exists("Zend_Registry")){ // if(class_exists("Zend_Registry")){
@@ -51,6 +49,7 @@ class BpmnEngine_Services_SearchIndex
$this->_solrHost = $solrHost; $this->_solrHost = $solrHost;
// } // }
} }
/** /**
* Verify if the Solr service is available * Verify if the Solr service is available
* @gearman = false * @gearman = false
@@ -59,8 +58,7 @@ class BpmnEngine_Services_SearchIndex
* *
* no input parameters @param[in] * no input parameters @param[in]
* *
* @param * @param [out] bool true if index service is enabled false in other case
* [out] bool true if index service is enabled false in other case
*/ */
public function isEnabled () public function isEnabled ()
{ {
@@ -77,10 +75,8 @@ class BpmnEngine_Services_SearchIndex
* @rest = false * @rest = false
* @background = false * @background = false
* *
* @param * @param [in] Entity_FacetRequest facetRequestEntity Facet request entity
* [in] Entity_FacetRequest facetRequestEntity Facet request entity * @param [out] array FacetGroup
* @param
* [out] array FacetGroup
*/ */
public function getFacetsList ($facetRequestEntity) public function getFacetsList ($facetRequestEntity)
{ {
@@ -99,10 +95,12 @@ class BpmnEngine_Services_SearchIndex
$facetRequestEntity->selectedFacetsString = str_replace( ',,', ',', $facetRequestEntity->selectedFacetsString ); $facetRequestEntity->selectedFacetsString = str_replace( ',,', ',', $facetRequestEntity->selectedFacetsString );
// remove descriptions of selected facet groups // remove descriptions of selected facet groups
$aGroups = explode( ',', $facetRequestEntity->selectedFacetsString ); $aGroups = explode( ',', $facetRequestEntity->selectedFacetsString );
$aGroups = array_filter( $aGroups ); // remove empty items $aGroups = array_filter( $aGroups ); // remove empty items
$aSelectedFacetGroups = array (); $aSelectedFacetGroups = array ();
foreach ($aGroups as $i => $value) { foreach ($aGroups as $i => $value) {
$gi = explode( ':::', $value ); $gi = explode( ':::', $value );
@@ -115,12 +113,7 @@ class BpmnEngine_Services_SearchIndex
if ($count == 0) { if ($count == 0) {
$removeCondition = str_replace( $value, '', $facetRequestEntity->selectedFacetsString, $count ); $removeCondition = str_replace( $value, '', $facetRequestEntity->selectedFacetsString, $count );
} }
$selectedFacetGroupData = array ( $selectedFacetGroupData = array ('selectedFacetGroupName' => $gr[0],'selectedFacetGroupPrintName' => $gr[1],'selectedFacetItemName' => $it[0],'selectedFacetItemPrintName' => $it[1],'selectedFacetRemoveCondition' => $removeCondition
'selectedFacetGroupName' => $gr [0],
'selectedFacetGroupPrintName' => $gr [1],
'selectedFacetItemName' => $it [0],
'selectedFacetItemPrintName' => $it [1],
'selectedFacetRemoveCondition' => $removeCondition
); );
$aSelectedFacetGroups[] = Entity_SelectedFacetGroupItem::createForRequest( $selectedFacetGroupData ); $aSelectedFacetGroups[] = Entity_SelectedFacetGroupItem::createForRequest( $selectedFacetGroupData );
@@ -136,11 +129,9 @@ class BpmnEngine_Services_SearchIndex
// exclude facetFields and facetDates included in filter from the next // exclude facetFields and facetDates included in filter from the next
// list of facets // list of facets
foreach ($aSelectedFacetGroups as $value) { foreach ($aSelectedFacetGroups as $value) {
$facetRequestEntity->facetFields = array_diff ($facetRequestEntity->facetFields, array ( $facetRequestEntity->facetFields = array_diff( $facetRequestEntity->facetFields, array ($value->selectedFacetGroupName
$value->selectedFacetGroupName
) ); ) );
$facetRequestEntity->facetDates = array_diff ($facetRequestEntity->facetDates, array ( $facetRequestEntity->facetDates = array_diff( $facetRequestEntity->facetDates, array ($value->selectedFacetGroupName
$value->selectedFacetGroupName
) ); ) );
} }
@@ -174,8 +165,7 @@ class BpmnEngine_Services_SearchIndex
foreach ($facetFieldsResult as $facetGroup => $facetvalues) { foreach ($facetFieldsResult as $facetGroup => $facetvalues) {
if (count( $facetvalues ) > 0) // if the group have facets included if (count( $facetvalues ) > 0) // if the group have facets included
{ {
$data = array ( $data = array ('facetGroupName' => $facetGroup
'facetGroupName' => $facetGroup
); );
$data['facetGroupPrintName'] = $facetGroup; $data['facetGroupPrintName'] = $facetGroup;
$data['facetGroupType'] = 'field'; $data['facetGroupType'] = 'field';
@@ -206,8 +196,7 @@ class BpmnEngine_Services_SearchIndex
if (count( (array) $facetvalues ) > 3) // if the group have any facets included if (count( (array) $facetvalues ) > 3) // if the group have any facets included
// besides start, end and gap // besides start, end and gap
{ {
$data = array ( $data = array ('facetGroupName' => $facetGroup
'facetGroupName' => $facetGroup
); );
$data['facetGroupPrintName'] = $facetGroup; $data['facetGroupPrintName'] = $facetGroup;
$data['facetGroupType'] = 'daterange'; $data['facetGroupType'] = 'daterange';
@@ -220,8 +209,7 @@ class BpmnEngine_Services_SearchIndex
$dataItem['facetName'] = '[' . $k . '%20TO%20' . $facetvalueskeys[$i + 1] . ']'; $dataItem['facetName'] = '[' . $k . '%20TO%20' . $facetvalueskeys[$i + 1] . ']';
$dataItem['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalueskeys[$i + 1] . ']'; $dataItem['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalueskeys[$i + 1] . ']';
} } else {
else {
// the last group // the last group
$dataItem['facetName'] = '[' . $k . '%20TO%20' . $facetvalues->end . ']'; $dataItem['facetName'] = '[' . $k . '%20TO%20' . $facetvalues->end . ']';
$dataItem['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalues->end . ']'; $dataItem['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalues->end . ']';
@@ -255,14 +243,12 @@ class BpmnEngine_Services_SearchIndex
$filterText = substr_replace( $filterText, '', - 1 ); $filterText = substr_replace( $filterText, '', - 1 );
// $filterText = ($filterText == '')?'':'&filterText='.$filterText; // $filterText = ($filterText == '')?'':'&filterText='.$filterText;
/** /**
* *************************************************************** * ***************************************************************
*/ */
// Create result // Create result
$dataFacetResult = array ( $dataFacetResult = array ('aFacetGroups' => $facetGroups,'aSelectedFacetGroups' => $aSelectedFacetGroups,'sFilterText' => $filterText
'aFacetGroups' => $facetGroups,
'aSelectedFacetGroups' => $aSelectedFacetGroups,
'sFilterText' => $filterText
); );
$facetResult = Entity_FacetResult::createForRequest( $dataFacetResult ); $facetResult = Entity_FacetResult::createForRequest( $dataFacetResult );
@@ -271,6 +257,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Get the total number of documents in search server * Get the total number of documents in search server
*
* @param string $workspace * @param string $workspace
* @return integer number of documents * @return integer number of documents
* *
@@ -290,6 +277,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Update document Index * Update document Index
*
* @param SolrUpdateDocumentEntity $solrUpdateDocumentEntity * @param SolrUpdateDocumentEntity $solrUpdateDocumentEntity
*/ */
public function updateIndexDocument ($solrUpdateDocumentEntity) public function updateIndexDocument ($solrUpdateDocumentEntity)
@@ -304,6 +292,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Delete document from index * Delete document from index
*
* @param string $workspace * @param string $workspace
* @param string $idQuery * @param string $idQuery
*/ */
@@ -319,6 +308,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Commit index changes * Commit index changes
*
* @param string $workspace * @param string $workspace
*/ */
public function commitIndexChanges ($workspace) public function commitIndexChanges ($workspace)
@@ -333,6 +323,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Optimize index changes * Optimize index changes
*
* @param string $workspace * @param string $workspace
*/ */
public function optimizeIndexChanges ($workspace) public function optimizeIndexChanges ($workspace)
@@ -347,6 +338,7 @@ class BpmnEngine_Services_SearchIndex
/** /**
* Call Solr server to return the list of paginated pages. * Call Solr server to return the list of paginated pages.
*
* @param FacetRequest $solrRequestData * @param FacetRequest $solrRequestData
* @return Entity_SolrQueryResult * @return Entity_SolrQueryResult
*/ */
@@ -374,6 +366,7 @@ class BpmnEngine_Services_SearchIndex
// $solrRequestData->includeCols = array_diff($solrRequestData->includeCols, // $solrRequestData->includeCols = array_diff($solrRequestData->includeCols,
// array('')); // array(''));
// execute query // execute query
$solr = new BpmnEngine_SearchIndexAccess_Solr( $this->_solrIsEnabled, $this->_solrHost ); $solr = new BpmnEngine_SearchIndexAccess_Solr( $this->_solrIsEnabled, $this->_solrHost );
$solrPaginatedResult = $solr->executeQuery( $solrRequestData ); $solrPaginatedResult = $solr->executeQuery( $solrRequestData );
@@ -387,13 +380,11 @@ class BpmnEngine_Services_SearchIndex
$docs = $solrPaginatedResult->response->docs; $docs = $solrPaginatedResult->response->docs;
// print_r($docs); // print_r($docs);
// insert list of names in docs result // insert list of names in docs result
$data = array ( $data = array ("sEcho" => '', // must be completed in response
"sEcho" => '', // must be completed in response
"iTotalRecords" => intval( $numTotalDocs ), // we must get the "iTotalRecords" => intval( $numTotalDocs ), // we must get the
// total number of // total number of
// documents // documents
"iTotalDisplayRecords" => $numFound, "iTotalDisplayRecords" => $numFound,"aaData" => array ()
"aaData" => array ()
); );
// copy result document or add placeholders to result // copy result document or add placeholders to result
foreach ($docs as $i => $doc) { foreach ($docs as $i => $doc) {
@@ -401,12 +392,10 @@ class BpmnEngine_Services_SearchIndex
foreach ($solrRequestData->includeCols as $columnName) { foreach ($solrRequestData->includeCols as $columnName) {
if ($columnName == '') { if ($columnName == '') {
$data['aaData'][$i][] = ''; // placeholder $data['aaData'][$i][] = ''; // placeholder
} } else {
else {
if (isset( $doc->$columnName )) { if (isset( $doc->$columnName )) {
$data['aaData'][$i][] = $doc->$columnName; $data['aaData'][$i][] = $doc->$columnName;
} } else {
else {
$data['aaData'][$i][] = ''; $data['aaData'][$i][] = '';
} }
} }
@@ -416,11 +405,13 @@ class BpmnEngine_Services_SearchIndex
$solrQueryResponse = Entity_SolrQueryResult::createForRequest( $data ); $solrQueryResponse = Entity_SolrQueryResult::createForRequest( $data );
// //
return $solrQueryResponse; return $solrQueryResponse;
} }
/** /**
* Return the list of stored fields in the index. * Return the list of stored fields in the index.
*
* @param string $workspace * @param string $workspace
* @return array of index fields * @return array of index fields
*/ */
@@ -441,8 +432,7 @@ class BpmnEngine_Services_SearchIndex
// $listFields[strtolower($originalFieldName)] = $key; //in case of case insentive strings // $listFields[strtolower($originalFieldName)] = $key; //in case of case insentive strings
// Maintain case sensitive variable names // Maintain case sensitive variable names
$listFields[$originalFieldName] = $key; $listFields[$originalFieldName] = $key;
} } else {
else {
// $listFields[strtolower($key)] = $key; // $listFields[strtolower($key)] = $key;
// Maintain case sensitive variable names // Maintain case sensitive variable names
$listFields[$key] = $key; $listFields[$key] = $key;