static function createForRequest($data) { $obj = new Entity_SolrQueryResult(); $obj->initializeObject($data); $requiredFields = array('sEcho', 'iTotalRecords', 'iTotalDisplayRecords', 'aaData'); $obj->validateRequiredFields($requiredFields); return $obj; }
/** * Call Solr server to return the list of paginated pages. * @param FacetRequest $solrRequestData * @return Entity_SolrQueryResult */ public function getDataTablePaginatedList($solrRequestData) { require_once 'class.solr.php'; require_once 'entities/SolrRequestData.php'; require_once 'entities/SolrQueryResult.php'; // prepare the list of sorted columns // verify if the data of sorting is available //if (isset ($solrRequestData->sortCols [0])) { // for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { // verify if column is sortable //if ($solrRequestData->includeCols [$solrRequestData->sortCols [$i]] != '' && $solrRequestData->sortableCols [$i] == "true") { // change sorting column index to column names //$solrRequestData->sortCols [$i] = $solrRequestData->includeCols [$solrRequestData->sortCols [$i]]; // define the direction of the sorting columns //$solrRequestData->sortDir [$i] = $solrRequestData->sortDir [$i]; //} // } //} // remove placeholder fields // the placeholder doesn't affect the the solr's response // $solrRequestData->includeCols = array_diff($solrRequestData->includeCols, // array('')); // execute query $solr = new BpmnEngine_SearchIndexAccess_Solr($this->_solrIsEnabled, $this->_solrHost); $solrPaginatedResult = $solr->executeQuery($solrRequestData); // get total number of documents in index $numTotalDocs = $solr->getNumberDocuments($solrRequestData->workspace); // create the Datatable response of the query $numFound = $solrPaginatedResult->response->numFound; $docs = $solrPaginatedResult->response->docs; // print_r($docs); // insert list of names in docs result $data = array("sEcho" => '', "iTotalRecords" => intval($numTotalDocs), "iTotalDisplayRecords" => $numFound, "aaData" => array()); // copy result document or add placeholders to result foreach ($docs as $i => $doc) { $data['aaData'][$i] = array(); foreach ($solrRequestData->includeCols as $columnName) { if ($columnName == '') { $data['aaData'][$i][] = ''; // placeholder } else { if (isset($doc->{$columnName})) { $data['aaData'][$i][$columnName] = $doc->{$columnName}; } else { $data['aaData'][$i][$columnName] = ''; } } } } $solrQueryResponse = Entity_SolrQueryResult::createForRequest($data); // return $solrQueryResponse; }