| @@ 30-115 (lines=86) @@ | ||
| 27 | * @package Elastification\Client\Request\Shared\Index |
|
| 28 | * @author Daniel Wendlandt |
|
| 29 | */ |
|
| 30 | abstract class AbstractBulkCreateRequest extends AbstractBaseRequest |
|
| 31 | { |
|
| 32 | const LINE_BREAK = "\n"; |
|
| 33 | const REQUEST_ACTION = '_bulk'; |
|
| 34 | const BULK_ACTION = 'create'; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var null|mixed |
|
| 38 | */ |
|
| 39 | private $body = null; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * This will overwrite getIndex method for returning null. |
|
| 43 | * The index property is only for internal use. |
|
| 44 | * |
|
| 45 | * @return null |
|
| 46 | */ |
|
| 47 | public function getIndex() |
|
| 48 | { |
|
| 49 | return null; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * This will overwrite getType method for returning null. |
|
| 54 | * The type property is only for internal use. |
|
| 55 | * |
|
| 56 | * @return null |
|
| 57 | */ |
|
| 58 | public function getType() |
|
| 59 | { |
|
| 60 | return null; |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @inheritdoc |
|
| 65 | */ |
|
| 66 | public function getMethod() |
|
| 67 | { |
|
| 68 | return RequestMethods::POST; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @inheritdoc |
|
| 73 | */ |
|
| 74 | public function getAction() |
|
| 75 | { |
|
| 76 | return self::REQUEST_ACTION; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @inheritdoc |
|
| 81 | */ |
|
| 82 | public function getBody() |
|
| 83 | { |
|
| 84 | return $this->body; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * @inheritdoc |
|
| 89 | */ |
|
| 90 | public function setBody($body) |
|
| 91 | { |
|
| 92 | //to nothing |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * adds a document to the body and transforms it in the right format. |
|
| 97 | * |
|
| 98 | * @param array|object $doc |
|
| 99 | * @param string $id |
|
| 100 | * @author Daniel Wendlandt |
|
| 101 | */ |
|
| 102 | public function addDocument($doc, $id = null) |
|
| 103 | { |
|
| 104 | $action = array( |
|
| 105 | self::BULK_ACTION => array( |
|
| 106 | '_id' => $id, |
|
| 107 | '_index' => $this->index, |
|
| 108 | '_type' => $this->type |
|
| 109 | ) |
|
| 110 | ); |
|
| 111 | ||
| 112 | $this->body .= json_encode($action) . self::LINE_BREAK; |
|
| 113 | $this->body .= $this->serializer->serialize($doc, $this->serializerParams) . self::LINE_BREAK; |
|
| 114 | } |
|
| 115 | } |
|
| 116 | ||
| @@ 30-115 (lines=86) @@ | ||
| 27 | * @package Elastification\Client\Request\Shared\Index |
|
| 28 | * @author Daniel Wendlandt |
|
| 29 | */ |
|
| 30 | abstract class AbstractBulkIndexRequest extends AbstractBaseRequest |
|
| 31 | { |
|
| 32 | const LINE_BREAK = "\n"; |
|
| 33 | const REQUEST_ACTION = '_bulk'; |
|
| 34 | const BULK_ACTION = 'index'; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var null|mixed |
|
| 38 | */ |
|
| 39 | private $body = null; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * This will overwrite getIndex method for returning null. |
|
| 43 | * The index property is only for internal use. |
|
| 44 | * |
|
| 45 | * @return null |
|
| 46 | */ |
|
| 47 | public function getIndex() |
|
| 48 | { |
|
| 49 | return null; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * This will overwrite getType method for returning null. |
|
| 54 | * The type property is only for internal use. |
|
| 55 | * |
|
| 56 | * @return null |
|
| 57 | */ |
|
| 58 | public function getType() |
|
| 59 | { |
|
| 60 | return null; |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @inheritdoc |
|
| 65 | */ |
|
| 66 | public function getMethod() |
|
| 67 | { |
|
| 68 | return RequestMethods::POST; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @inheritdoc |
|
| 73 | */ |
|
| 74 | public function getAction() |
|
| 75 | { |
|
| 76 | return self::REQUEST_ACTION; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @inheritdoc |
|
| 81 | */ |
|
| 82 | public function getBody() |
|
| 83 | { |
|
| 84 | return $this->body; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * @inheritdoc |
|
| 89 | */ |
|
| 90 | public function setBody($body) |
|
| 91 | { |
|
| 92 | //to nothing |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * adds a document to the body and transforms it in the right format. |
|
| 97 | * |
|
| 98 | * @param array|object $doc |
|
| 99 | * @param string $id |
|
| 100 | * @author Daniel Wendlandt |
|
| 101 | */ |
|
| 102 | public function addDocument($doc, $id = null) |
|
| 103 | { |
|
| 104 | $action = array( |
|
| 105 | self::BULK_ACTION => array( |
|
| 106 | '_id' => $id, |
|
| 107 | '_index' => $this->index, |
|
| 108 | '_type' => $this->type |
|
| 109 | ) |
|
| 110 | ); |
|
| 111 | ||
| 112 | $this->body .= json_encode($action) . self::LINE_BREAK; |
|
| 113 | $this->body .= $this->serializer->serialize($doc, $this->serializerParams) . self::LINE_BREAK; |
|
| 114 | } |
|
| 115 | } |
|
| 116 | ||