/** * Adds the collected documents to the Solr index. * * @param array $documents An array of \Apache_Solr_Document objects. * @return boolean TRUE if documents were added successfully, FALSE otherwise */ protected function addDocumentsToSolrIndex(array $documents) { $documentsAdded = FALSE; if (!count($documents)) { return $documentsAdded; } try { $this->log('Adding ' . count($documents) . ' documents.', 0, $documents); // chunk adds by 20 $documentChunks = array_chunk($documents, 20); foreach ($documentChunks as $documentChunk) { $response = $this->solrConnection->addDocuments($documentChunk); if ($response->getHttpStatus() != 200) { $transportException = new \Apache_Solr_HttpTransportException($response); throw new \RuntimeException('Solr Request failed.', 1331834983, $transportException); } } $documentsAdded = TRUE; } catch (\Exception $e) { $this->log($e->getMessage() . ' Error code: ' . $e->getCode(), 2); if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['exceptions']) { GeneralUtility::devLog('Exception while adding documents', 'solr', 3, array($e->__toString())); } } return $documentsAdded; }
/** * Creates a single Solr Document for an item in a specific language. * * @param Item $item An index queue item to index. * @param integer $language The language to use. * @return boolean TRUE if item was indexed successfully, FALSE on failure */ protected function indexItem(Item $item, $language = 0) { $itemIndexed = FALSE; $documents = array(); $itemDocument = $this->itemToDocument($item, $language); if (is_null($itemDocument)) { /* * If there is no itemDocument, this means there was no translation * for this record. This should not stop the current item to count as * being valid because not-indexing not-translated items is perfectly * fine. */ return TRUE; } $documents[] = $itemDocument; $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument)); $documents = $this->processDocuments($item, $documents); $documents = $this->preAddModifyDocuments($item, $language, $documents); $response = $this->solr->addDocuments($documents); if ($response->getHttpStatus() == 200) { $itemIndexed = TRUE; } $this->log($item, $documents, $response); return $itemIndexed; }