public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $type = new Type($index, 'helloworld');
     $doc = new Document(1, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'emil', 'test' => array('1', '3', '6')));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '*****@*****.**', 'username' => 'ruth', 'test' => array('2', '3', '7')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $boolQuery = new Bool();
     $termQuery1 = new Term(array('test' => '2'));
     $boolQuery->addMust($termQuery1);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(2, $resultSet->count());
     $termQuery2 = new Term(array('test' => '5'));
     $boolQuery->addMust($termQuery2);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(1, $resultSet->count());
     $termQuery3 = new Term(array('username' => 'hans'));
     $boolQuery->addMust($termQuery3);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(1, $resultSet->count());
     $termQuery4 = new Term(array('username' => 'emil'));
     $boolQuery->addMust($termQuery4);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(0, $resultSet->count());
 }
 /**
  * @group functional
  */
 public function testSearchByDocument()
 {
     $client = $this->_getClient(array('persistent' => false));
     $index = $client->getIndex('elastica_test');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $type = new Type($index, 'mlt_test');
     $type->addDocuments(array(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')), new Document(2, array('visible' => true, 'name' => 'bruce wayne')), new Document(3, array('visible' => false, 'name' => 'bruce wayne')), new Document(4, array('visible' => true, 'name' => 'batman')), new Document(5, array('visible' => false, 'name' => 'batman')), new Document(6, array('visible' => true, 'name' => 'superman')), new Document(7, array('visible' => true, 'name' => 'spiderman'))));
     $index->refresh();
     $doc = $type->getDocument(1);
     // Return all similar from id
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(4, $resultSet->count());
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar from id
     $filter = new Query\BoolQuery();
     $filterTerm = new Query\Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     // Return all similar from source
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinimumShouldMatch(90);
     $mltQuery->setLike($type->getDocument(1)->setId(''));
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(1, $resultSet->count());
     // Legacy test with filter
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar
     $filter = new BoolFilter();
     $filterTerm = new Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
 }
 /**
  * @group functional
  */
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldmlt');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', 'content' => 'This is a fake nospam email address for gmail'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $mltQuery = new MoreLikeThis();
     $mltQuery->setLikeText('fake gmail sample');
     $mltQuery->setFields(array('email', 'content'));
     $mltQuery->setMaxQueryTerms(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinTermFrequency(1);
     $query = new Query();
     $query->setFields(array('email', 'content'));
     $query->setQuery($mltQuery);
     $resultSet = $type->search($query);
     $resultSet->getResponse()->getData();
     $this->assertEquals(2, $resultSet->count());
 }
 public function testQuery()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $type = new Type($index, 'constant_score');
     $doc = new Document(1, array('id' => 1, 'email' => '*****@*****.**', 'username' => 'hans'));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'emil'));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '*****@*****.**', 'username' => 'ruth'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $boost = 1.3;
     $query_match = new MatchAll();
     $query = new ConstantScore();
     $query->setQuery($query_match);
     $query->setBoost($boost);
     $expectedArray = array('constant_score' => array('query' => $query_match->toArray(), 'boost' => $boost));
     $this->assertEquals($expectedArray, $query->toArray());
     $resultSet = $type->search($query);
     $results = $resultSet->getResults();
     $this->assertEquals($resultSet->count(), 3);
     $this->assertEquals($results[1]->getScore(), 1);
 }
 public function testNegativeBoost()
 {
     $keyword = "vital";
     $negativeKeyword = "mercury";
     $query = new Boosting();
     $positiveQuery = new \Elastica\Query\Term(array('name' => $keyword));
     $negativeQuery = new \Elastica\Query\Term(array('name' => $negativeKeyword));
     $query->setPositiveQuery($positiveQuery);
     $query->setNegativeQuery($negativeQuery);
     $query->setNegativeBoost(0.2);
     $response = $this->type->search($query);
     $results = $response->getResults();
     $this->assertEquals($response->getTotalHits(), 4);
     $lastResult = $results[3]->getData();
     $this->assertEquals($lastResult['name'], $this->sampleData[2]['name']);
 }
 /**
  * @group functional
  */
 public function testSearch()
 {
     $index = $this->_createIndex();
     $index->getSettings()->setNumberOfReplicas(0);
     $type = new Type($index, 'helloworld');
     $doc = new Document(1, array('email' => '*****@*****.**', 'username' => 'test 7/6 123', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $queryString = new QueryString(Util::escapeTerm('test 7/6'));
     $resultSet = $type->search($queryString);
     $this->assertEquals(1, $resultSet->count());
 }
 public function testScriptScore()
 {
     $scriptString = "_score * doc['price'].value";
     $script = new Script($scriptString);
     $query = new FunctionScore();
     $query->addScriptScoreFunction($script);
     $expected = array('function_score' => array('functions' => array(array('script_score' => array('script' => $scriptString)))));
     $this->assertEquals($expected, $query->toArray());
     $response = $this->type->search($query);
     $results = $response->getResults();
     // the document the highest price should be scored highest
     $result0 = $results[0]->getData();
     $this->assertEquals("Miller's Field", $result0['name']);
 }
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworld');
     $doc = new Document(1, array('email' => '*****@*****.**', 'username' => 'hanswurst', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $queryString = new QueryString('test*');
     $resultSet = $type->search($queryString);
     $this->assertEquals(1, $resultSet->count());
 }
示例#9
0
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldfuzzy');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->setLikeText("sample gmail");
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setMinSimilarity(0.3);
     $fltQuery->setMaxQueryTerms(3);
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
 }
示例#10
0
 public function testAddWordxFile()
 {
     $indexMapping = array('file' => array('type' => 'attachment'), 'text' => array('type' => 'string', 'store' => 'no'));
     $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0));
     $index = $this->_createIndex();
     $type = new Type($index, 'content');
     $index->create($indexParams, true);
     $type->setMapping($indexMapping);
     $doc1 = new Document(1);
     $doc1->addFile('file', BASE_PATH . '/data/test.docx');
     $doc1->set('text', 'basel world');
     $type->addDocument($doc1);
     $doc2 = new Document(2);
     $doc2->set('text', 'running in basel');
     $type->addDocument($doc2);
     $index->optimize();
     $resultSet = $type->search('xodoa');
     $this->assertEquals(1, $resultSet->count());
     $resultSet = $type->search('basel');
     $this->assertEquals(2, $resultSet->count());
     $resultSet = $type->search('ruflin');
     $this->assertEquals(0, $resultSet->count());
 }
 private function reindexInternal(Type $type, Type $oldType, $children, $childNumber, $chunkSize, $retryAttempts)
 {
     $filter = null;
     $messagePrefix = "";
     if ($childNumber === 1 && $children === 1) {
         $this->outputIndented("\t\tStarting single process reindex\n");
     } else {
         if ($childNumber >= $children) {
             $this->error("Invalid parameters - childNumber >= children ({$childNumber} >= {$children}) ", 1);
         }
         $messagePrefix = "\t\t[{$childNumber}] ";
         $this->outputIndented($messagePrefix . "Starting child process reindex\n");
         // Note that it is not ok to abs(_uid.hashCode) because hashCode(Integer.MIN_VALUE) == Integer.MIN_VALUE
         $filter = new \CirrusSearch\Extra\Filter\IdHashMod($children, $childNumber);
     }
     $properties = $this->mappingConfig[$oldType->getName()]['properties'];
     try {
         $query = new Query();
         $query->setFields(array('_id', '_source'));
         if ($filter) {
             $query->setQuery(new \Elastica\Query\Filtered(new \Elastica\Query\MatchAll(), $filter));
         }
         // Note here we dump from the current index (using the alias) so we can use Connection::getPageType
         $result = $oldType->search($query, array('search_type' => 'scan', 'scroll' => '1h', 'size' => $chunkSize));
         $totalDocsToReindex = $result->getResponse()->getData();
         $totalDocsToReindex = $totalDocsToReindex['hits']['total'];
         $this->outputIndented($messagePrefix . "About to reindex {$totalDocsToReindex} documents\n");
         $operationStartTime = microtime(true);
         $completed = 0;
         $self = $this;
         Util::iterateOverScroll($this->index, $result->getResponse()->getScrollId(), '1h', function ($results) use($properties, $retryAttempts, $messagePrefix, $self, $type, &$completed, $totalDocsToReindex, $operationStartTime) {
             $documents = array();
             foreach ($results as $result) {
                 $documents[] = $self->buildNewDocument($result, $properties);
             }
             $self->withRetry($retryAttempts, $messagePrefix, 'retrying as singles', function () use($self, $type, $messagePrefix, $documents) {
                 $self->sendDocuments($type, $messagePrefix, $documents);
             });
             $completed += sizeof($results);
             $rate = round($completed / (microtime(true) - $operationStartTime));
             $this->outputIndented($messagePrefix . "Reindexed {$completed}/{$totalDocsToReindex} documents at {$rate}/second\n");
         }, 0, $retryAttempts, function ($e, $errors) use($self, $messagePrefix) {
             $self->sleepOnRetry($e, $errors, $messagePrefix, 'fetching documents to reindex');
         });
         $this->outputIndented($messagePrefix . "All done\n");
     } catch (ExceptionInterface $e) {
         // Note that we can't fail the master here, we have to check how many documents are in the new index in the master.
         $type = get_class($e);
         $message = ElasticsearchIntermediary::extractMessage($e);
         LoggerFactory::getInstance('CirrusSearch')->warning("Search backend error during reindex.  Error type is '{type}' and message is:  {message}", array('type' => $type, 'message' => $message));
         die(1);
     }
 }
示例#12
0
 /**
  * @group functional
  */
 public function testOldObject()
 {
     if (version_compare(phpversion(), 7, '>=')) {
         self::markTestSkipped('These objects are not supported in PHP 7');
     }
     $index = $this->_createIndex();
     $type = new Type($index, 'test');
     $docNumber = 3;
     for ($i = 0; $i < $docNumber; ++$i) {
         $doc = new Document($i, array('email' => '*****@*****.**'));
         $type->addDocument($doc);
     }
     $index->refresh();
     $this->hideDeprecated();
     $boolQuery = new \Elastica\Query\Bool();
     $this->showDeprecated();
     $resultSet = $type->search($boolQuery);
     $this->assertEquals($resultSet->count(), $docNumber);
 }
示例#13
0
 /**
  * @group functional
  */
 public function testAddObject()
 {
     $index = $this->_createIndex();
     $type = new Type($index, 'user');
     $type->setSerializer('get_object_vars');
     $userObject = new \stdClass();
     $userObject->username = '******';
     $userObject->test = array('2', '3', '5');
     $type->addObject($userObject);
     $index->refresh();
     $resultSet = $type->search('hans');
     $this->assertEquals(1, $resultSet->count());
     // Test if source is returned
     $result = $resultSet->current();
     $data = $result->getData();
     $this->assertEquals('hans', $data['username']);
 }
 public function testSearchSetAnalyzer()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array('analysis' => array('analyzer' => array('searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('myStopWords'))), 'filter' => array('myStopWords' => array('type' => 'stop', 'stopwords' => array('The'))))), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldfuzzy');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => '*****@*****.**', 'content' => 'The Fuzzy Test!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', 'content' => 'Elastica Fuzzy Test'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setLikeText("The");
     $fltQuery->setMinSimilarity(0.1);
     $fltQuery->setMaxQueryTerms(3);
     // Test before analyzer applied, should return 1 result
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
     $fltQuery->setParam('analyzer', 'searchAnalyzer');
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(0, $resultSet->count());
 }
示例#15
0
 /**
  * @Testing count
  */
 public function testCount()
 {
     $index = $this->_createIndex();
     $type = new Type($index, 'user');
     // Adds a list of documents with _bulk upload to the index
     $docs = array();
     $docs[] = new Document(2, array('username' => 'rolf', 'test' => array('1', '3', '6')));
     $docs[] = new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7')));
     $type->addDocuments($docs);
     $index->refresh();
     $resultSet = $type->search('rolf');
     $this->assertEquals(2, $resultSet->count());
     $count = $type->count('rolf');
     $this->assertEquals(2, $count);
     $resultSet = $type->count('rolf', true);
     $this->assertEquals(2, $resultSet->count());
     // Test if source is returned
     $result = $resultSet->current();
     $data = $result->getData();
     $this->assertEquals('rolf', $data['username']);
 }
示例#16
0
 /**
  * @group functional
  */
 public function testOldObject()
 {
     if (version_compare(phpversion(), 7, '>=')) {
         self::markTestSkipped('These objects are not supported in PHP 7');
     }
     $index = $this->_createIndex();
     $type = new Type($index, 'test');
     $docNumber = 3;
     for ($i = 0; $i < $docNumber; ++$i) {
         $doc = new Document($i, array('email' => '*****@*****.**'));
         $type->addDocument($doc);
     }
     $index->refresh();
     $err = array();
     set_error_handler(function () use(&$err) {
         $err[] = func_get_args();
     });
     $boolQuery = new \Elastica\Query\Bool();
     restore_error_handler();
     $this->assertCount(1, $err);
     $this->assertEquals(E_USER_DEPRECATED, $err[0][0]);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals($resultSet->count(), $docNumber);
 }
示例#17
0
 /**
  * @group functional
  */
 public function testNoSource()
 {
     $index = $this->_createIndex();
     $type = new Type($index, 'user');
     // Adds 1 document to the index
     $doc1 = new Document(1, array('username' => 'ruflin', 'test' => array('2', '3', '5')));
     $type->addDocument($doc1);
     // To update index
     $index->refresh();
     $query = Query::create('ruflin');
     $resultSet = $type->search($query);
     // Disable source
     $query->setSource(false);
     $resultSetNoSource = $type->search($query);
     $this->assertEquals(1, $resultSet->count());
     $this->assertEquals(1, $resultSetNoSource->count());
     // Tests if no source is in response except id
     $result = $resultSetNoSource->current();
     $this->assertEquals(1, $result->getId());
     $this->assertEmpty($result->getData());
     // Tests if source is in response except id
     $result = $resultSet->current();
     $this->assertEquals(1, $result->getId());
     $this->assertNotEmpty($result->getData());
 }
示例#18
0
 /**
  * @param array $params
  *
  * @return array
  */
 public function getResults(array $params)
 {
     $locale = $this->context->get('language');
     $brand = $this->context->get('brand');
     $brands = array_keys($this->context->getValues('brand'));
     $results = array();
     $params = array_merge(array('term' => '', 'method' => 'lieu'), $params);
     if ('lieu' == ($method = $params['method'])) {
         $params['term'] = '';
     }
     $term = $params['term'];
     $localizedNameField = sprintf('names.%s', $locale);
     if (!in_array($method, array('lieu', 'location'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('term' => array('brandSlug' => $queryBrand));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array('name' => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array('name' => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $hotels = $this->hotelType->search($query);
         /** @var Result $hotel */
         foreach ($hotels as $hotel) {
             $hotel = $hotel->getSource();
             if ($hotel['active']) {
                 $result = array('brand' => $hotel['brandName'], 'brandId' => strtolower($hotel['brandSlug']), 'label' => (isset($params['hotel_name_brand']) and $params['hotel_name_brand']) ? sprintf('%s %s', $hotel['brandName'], $hotel['name']) : $hotel['name'], 'typeResult' => 'hotel', 'id' => $hotel['id'], 'activeLocationId' => $hotel['cityId'], 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.hotels'), 'cssClass' => 'lvl1', 'latLng' => $hotel['latLng']);
                 if ($method == 'lieu') {
                     $result['type'] = 'lieu';
                 }
                 $results[] = $result;
             }
         }
     }
     if (!in_array($method, array('lieu', 'hotel'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $cities = $this->cityType->search($query);
         /** @var Result $city */
         foreach ($cities as $city) {
             $city = $city->getSource();
             $results[] = array('label' => $city['names'][$locale], 'typeResult' => 'city', 'id' => $city['id'], 'activeLocationId' => sprintf('city%s', $city['id']), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.cities'), 'cssClass' => 'lvl1');
         }
     }
     if (!in_array($method, array('hotel', 'location'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $departments = $this->departmentType->search($query);
         /** @var Result $department */
         foreach ($departments as $department) {
             $department = $department->getSource();
             $cityIds = $department['citiesIds'];
             $cityIds = array_map(function ($cityId) {
                 return sprintf('city%s', $cityId);
             }, $cityIds);
             $result = array('label' => $department['names'][$locale], 'typeResult' => 'department', 'id' => $department['id'], 'activeLocationId' => implode(',', $cityIds), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.departments'), 'cssClass' => 'lvl1');
             if ($method == 'lieu') {
                 $result['type'] = 'lieu';
                 $result['cssClass'] = 'lvl3';
             }
             $results[] = $result;
         }
     }
     if (!in_array($method, array('hotel'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $regions = $this->regionType->search($query);
         /** @var Result $region */
         foreach ($regions as $region) {
             $region = $region->getSource();
             $result = array('label' => $region['names'][$locale], 'typeResult' => 'region', 'id' => $region['id'], 'activeLocationId' => sprintf('region%s', $region['id']), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.regions'), 'cssClass' => 'lvl1');
             if ($method == 'lieu') {
                 $result['type'] = 'lieu';
                 $result['cssClass'] = 'lvl2';
             }
             $results[] = $result;
         }
     }
     if (!in_array($method, array('hotel'))) {
         $queryBrands = array($brand);
         $brandTerms = array();
         if ('seh' == $brand) {
             $queryBrands = array_diff($brands, $queryBrands);
         }
         foreach ($queryBrands as $queryBrand) {
             $brandTerms[] = array('range' => array($queryBrand => array('gt' => 0)));
         }
         $queryArray = array('query' => array('filtered' => array('query' => array('match' => array($localizedNameField => array('query' => $term, 'operator' => 'and'))), 'filter' => array('bool' => array('should' => $brandTerms)))), 'sort' => array($localizedNameField => 'asc'));
         $query = new Query();
         $query->setParams($queryArray);
         $countries = $this->countryType->search($query);
         /** @var Result $country */
         foreach ($countries as $country) {
             $country = $country->getSource();
             $result = array('label' => $country['names'][$locale], 'typeResult' => 'country', 'id' => $country['id'], 'activeLocationId' => sprintf('country%s', $country['id']), 'nbResults' => '', 'category' => $this->translator->trans('form.search.autocomplete.countries'), 'cssClass' => 'lvl1');
             if ($method == 'lieu') {
                 $result['type'] = 'lieu';
             }
             $results[] = $result;
         }
     }
     return $results;
 }