Ejemplo n.º 1
0
 public function testCleanWithoutAggregations()
 {
     $this->status->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
     $requestData = ['query' => 'bool_query', 'queries' => ['bool_query' => ['queryReference' => [['ref' => 'bool_query_rm'], ['ref' => 'match_query'], ['ref' => 'filtered_query_to_filter2']], 'type' => 'boolQuery'], 'match_query' => ['value' => 'ok', 'type' => 'matchQuery', 'is_bind' => true], 'bool_query_rm' => ['queryReference' => [['ref' => 'match_query_rm'], ['ref' => 'filtered_query_to_query'], ['ref' => 'filtered_query_to_filter']], 'type' => 'boolQuery'], 'match_query_rm' => ['value' => '$some$', 'type' => 'matchQuery'], 'match_query_rm2' => ['value' => '$some2$', 'type' => 'matchQuery'], 'filtered_query_to_query' => ['queryReference' => [['ref' => 'match_query_rm2']], 'type' => 'filteredQuery'], 'filtered_query_to_filter' => ['filterReference' => [['ref' => 'bool_filter']], 'type' => 'filteredQuery'], 'filtered_query_to_filter2' => ['filterReference' => [['ref' => 'bool_filter2']], 'type' => 'filteredQuery']], 'filters' => ['bool_filter' => ['filterReference' => [['ref' => 'term_filter'], ['ref' => 'range_filter']], 'type' => 'boolFilter'], 'term_filter' => ['value' => '$val$', 'type' => 'termFilter'], 'range_filter' => ['from' => '$from$', 'to' => '$to$', 'type' => 'rangeFilter'], 'bool_filter2' => ['filterReference' => [['ref' => 'term_filter2']], 'type' => 'boolFilter'], 'term_filter2' => ['value' => 'value_good', 'type' => 'termFilter', 'is_bind' => true]]];
     $exceptedRequestData = ['query' => 'bool_query', 'queries' => ['bool_query' => ['queryReference' => [['ref' => 'match_query'], ['ref' => 'filtered_query_to_filter2']], 'type' => 'boolQuery'], 'match_query' => ['value' => 'ok', 'type' => 'matchQuery', 'is_bind' => true], 'filtered_query_to_filter2' => ['filterReference' => [['ref' => 'bool_filter2']], 'type' => 'filteredQuery']], 'filters' => ['bool_filter2' => ['filterReference' => [['ref' => 'term_filter2']], 'type' => 'boolFilter'], 'term_filter2' => ['value' => 'value_good', 'type' => 'termFilter', 'is_bind' => true]], 'aggregations' => []];
     $result = $this->cleaner->clean($requestData);
     $this->assertEquals($exceptedRequestData, $result);
 }
Ejemplo n.º 2
0
    /**
     * @expectedException \Magento\Framework\Search\Request\EmptyRequestDataException
     * @expectedExceptionMessage Request query and filter is not set
     */
    public function testCleanEmptyQueryAndFilter()
    {
        $this->status->expects($this->once())
            ->method('isEnabled')
            ->will($this->returnValue(true));
        $requestData = [
            'query' => 'bool_query',
            'queries' => [
                'bool_query' => [
                    'queryReference' => [
                        ['ref' => 'bool_query_rm'],
                        ['ref' => 'filtered_query_to_filter2'],
                    ],
                    'type' => 'boolQuery',
                ],
                'bool_query_rm' => [
                    'queryReference' => [
                        ['ref' => 'match_query_rm'],
                        ['ref' => 'filtered_query_to_query'],
                        ['ref' => 'filtered_query_to_filter'],
                    ],
                    'type' => 'boolQuery',
                ],
                'match_query_rm' => ['value' => '$some$', 'type' => 'matchQuery'],
                'match_query_rm2' => ['value' => '$some2$', 'type' => 'matchQuery'],
                'filtered_query_to_query' => [
                    'queryReference' => [['ref' => 'match_query_rm2']],
                    'type' => 'filteredQuery',
                ],
                'filtered_query_to_filter' => [
                    'filterReference' => [['ref' => 'bool_filter']],
                    'type' => 'filteredQuery',
                ],
                'filtered_query_to_filter2' => [
                    'filterReference' => [['ref' => 'bool_filter2']],
                    'type' => 'filteredQuery',
                ],
            ],
            'filters' => [
                'bool_filter' => [
                    'filterReference' => [['ref' => 'term_filter'], ['ref' => 'range_filter']],
                    'type' => 'boolFilter',
                ],
                'term_filter' => ['value' => '$val$', 'type' => 'termFilter'],
                'range_filter' => ['from' => '$from$', 'to' => '$to$', 'type' => 'rangeFilter'],
                'bool_filter2' => [
                    'filterReference' => [['ref' => 'term_filter2']],
                    'type' => 'boolFilter',
                ],
                'term_filter2' => ['value' => '$val$', 'type' => 'termFilter'],
            ],
        ];

        $this->cleaner->clean($requestData);
    }
Ejemplo n.º 3
0
 /**
  * Clean aggregations if we don't need to process them
  *
  * @return void
  */
 private function cleanAggregations()
 {
     if (!$this->aggregationStatus->isEnabled()) {
         $this->requestData['aggregations'] = [];
     } else {
         if (array_key_exists('aggregations', $this->requestData) && is_array($this->requestData['aggregations'])) {
             foreach ($this->requestData['aggregations'] as $aggregationName => $aggregationValue) {
                 switch ($aggregationValue['type']) {
                     case 'dynamicBucket':
                         if (is_string($aggregationValue['method']) && preg_match('/^\\$(.+)\\$$/si', $aggregationValue['method'])) {
                             unset($this->requestData['aggregations'][$aggregationName]);
                         }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Clean aggregations if we don't need to process them
  *
  * @return void
  */
 private function cleanAggregations()
 {
     if (!$this->aggregationStatus->isEnabled()) {
         $this->requestData['aggregations'] = [];
     }
 }