Пример #1
0
 /**
  * Tests toArray method.
  */
 public function testToArray()
 {
     $missingFilterMock = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\Filter\\MissingFilter')->disableOriginalConstructor()->getMock();
     $missingFilterMock->expects($this->once())->method('getType')->willReturn('test_type');
     $missingFilterMock->expects($this->once())->method('toArray')->willReturn('test_array');
     $query = new Query();
     $query->setQuery($missingFilterMock);
     $this->assertEquals(['test_type' => 'test_array'], $query->toArray());
 }
 /**
  * Returns array of links got by document id.
  *
  * @return array
  */
 protected function getUrlsByDocumentParameter()
 {
     if (count($this->documentParamCache) < 1) {
         return [];
     }
     $urls = [];
     $query = new Query();
     $queryTerms = [];
     foreach ($this->documentParamCache as $param) {
         $queryTerms[$param[0]][] = $param[1];
     }
     foreach ($queryTerms as $field => $values) {
         $termQuery = new TermQuery($field, $values);
         $query->addQuery($termQuery, 'should');
     }
     $limitFilter = new LimitFilter(count($this->documentParamCache));
     $repository = $this->manager->getRepository('MultiModel');
     $search = $repository->createSearch()->addQuery($query)->addFilter($limitFilter);
     $documents = $repository->execute($search);
     // Add all category urls to invalidate.
     foreach ($documents as $document) {
         if (is_array($document->url)) {
             foreach ($document->url as $url) {
                 $urls[] = $url['url'];
             }
         }
     }
     array_walk($urls, [$this, 'addWildcard']);
     $this->addUrls($urls);
     return $urls;
 }