| Total Complexity | 8 |
| Total Lines | 98 |
| Duplicated Lines | 0 % |
| Coverage | 54.29% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | class SolrWriteService extends AbstractSolrService |
||
| 28 | { |
||
| 29 | const EXTRACT_SERVLET = 'update/extract'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Performs a content and meta data extraction request. |
||
| 33 | * |
||
| 34 | * @param Query $query An extraction query |
||
| 35 | * @return array An array containing the extracted content [0] and meta data [1] |
||
| 36 | */ |
||
| 37 | 1 | public function extractByQuery(Query $query) |
|
| 38 | { |
||
| 39 | try { |
||
| 40 | 1 | $response = $this->createAndExecuteRequest($query); |
|
| 41 | 1 | return [$response->file, (array)$response->file_metadata]; |
|
| 42 | } catch (\Exception $e) { |
||
| 43 | $param = $query->getRequestBuilder()->build($query)->getParams(); |
||
| 44 | $this->logger->log( |
||
| 45 | SolrLogManager::ERROR, |
||
| 46 | 'Extracting text and meta data through Solr Cell over HTTP POST', |
||
| 47 | [ |
||
| 48 | 'query' => (array)$query, |
||
| 49 | 'parameters' => $param, |
||
| 50 | 'file' => $query->getFile(), |
||
| 51 | 'query url' => self::EXTRACT_SERVLET, |
||
| 52 | 'exception' => $e->getMessage() |
||
| 53 | ] |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | return []; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Deletes all index documents of a certain type and does a commit |
||
| 62 | * afterwards. |
||
| 63 | * |
||
| 64 | * @param string $type The type of documents to delete, usually a table name. |
||
| 65 | * @param bool $commit Will commit immediately after deleting the documents if set, defaults to TRUE |
||
| 66 | */ |
||
| 67 | public function deleteByType($type, $commit = true) |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Create a delete document based on a query and submit it |
||
| 78 | * |
||
| 79 | * @param string $rawQuery Expected to be utf-8 encoded |
||
| 80 | * @return ResponseAdapter |
||
| 81 | */ |
||
| 82 | 14 | public function deleteByQuery($rawQuery) { |
|
| 83 | 14 | $query = $this->client->createUpdate(); |
|
| 84 | 14 | $query->addDeleteQuery($rawQuery); |
|
| 85 | 14 | return $this->createAndExecuteRequest($query); |
|
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Add an array of Solr Documents to the index all at once |
||
| 90 | * |
||
| 91 | * @param array $documents Should be an array of \ApacheSolrForTypo3\Solr\System\Solr\Document\Document instances |
||
| 92 | * @return ResponseAdapter |
||
| 93 | */ |
||
| 94 | 50 | public function addDocuments($documents) |
|
| 95 | { |
||
| 96 | 50 | $update = $this->client->createUpdate(); |
|
| 97 | 50 | $update->addDocuments($documents); |
|
| 98 | 50 | return $this->createAndExecuteRequest($update); |
|
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Send a commit command. Will be synchronous unless both wait parameters are set to false. |
||
| 103 | * |
||
| 104 | * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away |
||
| 105 | * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible |
||
| 106 | * @return ResponseAdapter |
||
| 107 | */ |
||
| 108 | 15 | public function commit($expungeDeletes = false, $waitSearcher = true) |
|
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Optimize the solr index |
||
| 117 | * |
||
| 118 | * @return Result |
||
| 119 | */ |
||
| 120 | 1 | public function optimizeIndex() |
|
| 127 |