/**
  * Test for Document Scan iterator.
  */
 public function testIterator()
 {
     $rawData = ['hits' => ['total' => 2, 'hits' => []]];
     $repository = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Repository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('scan')->with('test_id', '5m', Repository::RESULTS_RAW)->willReturn(['_scroll_id' => 'updated_id', 'hits' => ['total' => 2, 'hits' => [['id' => 1]]]]);
     $iterator = new DocumentScanIterator($rawData, [], []);
     $iterator->setRepository($repository)->setScrollId('test_id')->setScrollDuration('5m');
     $this->assertCount(2, $iterator);
     $this->assertTrue($iterator->valid());
 }
Ejemplo n.º 2
0
 /**
  * Parses raw result.
  *
  * @param array  $raw
  * @param string $resultsType
  * @param string $scrollDuration
  *
  * @return DocumentIterator|DocumentScanIterator|RawResultIterator|array
  *
  * @throws \Exception
  */
 private function parseResult($raw, $resultsType, $scrollDuration)
 {
     switch ($resultsType) {
         case self::RESULTS_OBJECT:
             if (isset($raw['_scroll_id'])) {
                 $iterator = new DocumentScanIterator($raw, $this->getManager()->getTypesMapping(), $this->getManager()->getBundlesMapping());
                 $iterator->setRepository($this)->setScrollDuration($scrollDuration)->setScrollId($raw['_scroll_id']);
                 return $iterator;
             }
             return new DocumentIterator($raw, $this->getManager()->getTypesMapping(), $this->getManager()->getBundlesMapping());
         case self::RESULTS_ARRAY:
             return $this->convertToNormalizedArray($raw);
         case self::RESULTS_RAW:
             return $raw;
         case self::RESULTS_RAW_ITERATOR:
             if (isset($raw['_scroll_id'])) {
                 $iterator = new RawResultScanIterator($raw);
                 $iterator->setRepository($this)->setScrollDuration($scrollDuration)->setScrollId($raw['_scroll_id']);
                 return $iterator;
             }
             return new RawResultIterator($raw);
         default:
             throw new \Exception('Wrong results type selected');
     }
 }