/**
  * Data provider for testToArray.
  *
  * @return array
  */
 public function getToArrayData()
 {
     $out = [];
     // Case #0 filter aggregation.
     $aggregation = new FilterAggregation('test_agg');
     $filter = new MatchAllQuery();
     $aggregation->setFilter($filter);
     $result = ['filter' => $filter->toArray()];
     $out[] = [$aggregation, $result];
     // Case #1 nested filter aggregation.
     $aggregation = new FilterAggregation('test_agg');
     $aggregation->setFilter($filter);
     $histogramAgg = new HistogramAggregation('acme', 'bar', 10);
     $aggregation->addAggregation($histogramAgg);
     $result = ['filter' => $filter->toArray(), 'aggregations' => [$histogramAgg->getName() => $histogramAgg->toArray()]];
     $out[] = [$aggregation, $result];
     // Case #2 testing bool filter.
     $aggregation = new FilterAggregation('test_agg');
     $matchAllFilter = new MatchAllQuery();
     $termFilter = new TermQuery('acme', 'foo');
     $boolFilter = new BoolQuery();
     $boolFilter->add($matchAllFilter);
     $boolFilter->add($termFilter);
     $aggregation->setFilter($boolFilter);
     $result = ['filter' => $boolFilter->toArray()];
     $out[] = [$aggregation, $result];
     return $out;
 }
Пример #2
0
 /**
  * Test if simplified structure is returned in case single MUST query given.
  */
 public function testSingleMust()
 {
     $bool = new BoolQuery();
     $bool->add(new TermQuery('key2', 'value2'), BoolQuery::MUST);
     $expected = ['term' => ['key2' => 'value2']];
     $this->assertEquals($expected, $bool->toArray());
 }
 /**
  * {@inheritdoc}
  */
 public function buildQuery(ShopContextInterface $context, $term)
 {
     $boolQuery = new BoolQuery();
     $boolQuery->addParameter('minimum_should_match', 1);
     $boolQuery->add($this->getBestFieldQuery($term), BoolQuery::SHOULD);
     $boolQuery->add($this->getPhrasePrefixQuery($term), BoolQuery::SHOULD);
     return $boolQuery;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function addBuilder(BuilderInterface $builder, $parameters = [])
 {
     if (!$this->query && !(array_key_exists('bool_type', $parameters) && !empty($parameters['bool_type']))) {
         $this->setBuilder($builder);
     } else {
         $parameters = $this->resolver->resolve(array_filter($parameters));
         $this->isBool() ?: $this->convertToBool();
         $this->query->add($builder, $parameters['bool_type']);
     }
     return $this;
 }
Пример #5
0
 /**
  * Test history action.
  */
 public function testHistoryAction()
 {
     $this->getManager();
     $client = self::createClient();
     $requestContent = json_encode(['key' => 'foo', 'domain' => 'barbar', 'locale' => 'en']);
     $client->request('POST', '/translate/_api/history', [], [], [], $requestContent);
     $this->assertTrue($client->getResponse()->isOk(), 'Controller response should be 200.');
     $manager = $this->getManager('default', false);
     $repository = $manager->getRepository('ONGRTranslationsBundle:History');
     $boolFilter = new BoolQuery();
     $boolFilter->add(new TermFilter('key', 'foo'));
     $boolFilter->add(new TermFilter('domain', 'barbar'));
     $boolFilter->add(new TermFilter('locale', 'en'));
     $search = $repository->createSearch()->addFilter($boolFilter);
     $results = $repository->execute($search, Repository::RESULTS_ARRAY);
     $this->assertEquals($results, json_decode($client->getResponse()->getContent(), true), 'History should be received.');
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function getAll($boolType = null)
 {
     return $this->bool->getQueries($boolType);
 }
Пример #7
0
 /**
  * @param Struct\ListProduct $product
  * @return BoolQuery
  */
 protected function getSimilarQuery(Struct\ListProduct $product)
 {
     $categories = $this->getProductCategories($product);
     $queries = [new FuzzyLikeThisFieldQuery('name', $product->getName(), ['boost' => 5]), new TermsQuery('categoryIds', $categories)];
     $query = new BoolQuery();
     $query->addParameter('minimum_should_match', 1);
     foreach ($queries as $bool) {
         $query->add($bool, BoolQuery::SHOULD);
     }
     return $query;
 }
Пример #8
0
 if (!empty($_GET['q']) && mb_strlen(trim($_GET['q'])) > 0) {
     $SearchQuery = preg_replace(new RegExp('[^\\w\\d\\s\\*\\?]'), '', trim($_GET['q']));
     $title .= "{$SearchQuery} - ";
     if (preg_match(new RegExp('[\\*\\?]'), $SearchQuery)) {
         $queryString = new ElasticsearchDSL\Query\QueryStringQuery($SearchQuery, ['fields' => ['label^20', 'tags'], 'default_operator' => 'and', 'phrase_slop' => 3]);
         $search->addQuery($queryString);
         $orderByID = false;
     } else {
         $multiMatch = new ElasticsearchDSL\Query\MultiMatchQuery(['label^20', 'tags'], $SearchQuery, ['type' => 'cross_fields', 'minimum_should_match' => '100%']);
         $search->addQuery($multiMatch);
     }
 } else {
     $sort = new ElasticsearchDSL\Sort\FieldSort('order', 'asc');
     $search->addSort($sort);
 }
 $boolquery = new BoolQuery();
 if (Permission::insufficient('staff')) {
     $boolquery->add(new TermQuery('private', true), BoolQuery::MUST_NOT);
 }
 $boolquery->add(new TermQuery('ishuman', $EQG), BoolQuery::MUST);
 $search->addQuery($boolquery);
 $search->setSource(false);
 $search = $search->toArray();
 $search = CGUtils::searchElastic($search, $Pagination);
 $Pagination->calcMaxPages($search['hits']['total']);
 if (!empty($search['hits']['hits'])) {
     $ids = [];
     foreach ($search['hits']['hits'] as $hit) {
         $ids[] = $hit['_id'];
     }
     $Ponies = $CGDb->where('id IN (' . implode(',', $ids) . ')')->orderBy('order', 'ASC')->get('appearances');
Пример #9
0
 /**
  * Test getType method.
  */
 public function testBoolGetType()
 {
     $bool = new BoolQuery();
     $result = $bool->getType();
     $this->assertEquals('bool', $result);
 }
Пример #10
0
 /**
  * Tests if BoolQuery::getQueries with specified bool type returns an array with added queries.
  */
 public function testGetQueriesByBoolTypeWithQueryAddedToBoolType()
 {
     $query = new TermQuery('key1', 'value1');
     $query2 = new TermQuery('key2', 'value2');
     $bool = new BoolQuery();
     $bool->add($query, BoolQuery::MUST, 'query');
     $bool->add($query2, BoolQuery::SHOULD, 'query2');
     $this->assertSame(array('query' => $query), $bool->getQueries(BoolQuery::MUST));
 }