private function searchCombination(SearchParameterBag $searchParams)
 {
     $query = new \Elastica_Query_Text();
     $query->setFieldQuery('name', $searchParams->get('term'));
     $query->setFieldParam('name', 'type', 'phrase_prefix');
     $this->results = $this->container->get('foq_elastica.finder.treatments')->find($query);
     $client = $this->container->get('foq_elastica.client');
     $search = new \Elastica_Search($client);
     $postType = $this->get('foq_elastica.index.acme.post');
     $tagType = $this->get('foq_elastica.index.acme.tag');
     // add the types to the search
     $search->addType($postType)->addType($tagType);
     $index = $this->get('foq_elastica.index');
     $search->addIndex($index);
     $searchTerm = $request->query->get('terms');
     $postSubjectQuery = new \Elastica_Query_Text();
     $postSubjectQuery->setFieldQuery('subject', $searchTerm);
     $postSubjectQuery->setFieldParam('subject', 'analyzer', 'snowball');
     $tagQuery = new \Elastica_Query_Text();
     $tagQuery->setFieldQuery('tagname', $searchTerm);
     $tagQuery->setFieldParam('tagname', 'analyzer', 'snowball');
     $boolQuery = new \Elastica_Query_Bool();
     $boolQuery->addShould($nameQuery);
     $boolQuery->addShould($keywordsQuery);
     $results = $search->search($boolQuery);
     return array('results' => $results);
 }
Пример #2
0
	public function testToArray() {
		$queryText = 'Nicolas Ruflin';
		$type = 'text_phrase';
		$analyzer = 'myanalyzer';
		$maxExpansions = 12;
		$field = 'test';

		$query = new Elastica_Query_Text();
		$query->setFieldQuery($field, $queryText);
		$query->setFieldType($field, $type);
		$query->setFieldParam($field, 'analyzer', $analyzer);
		$query->setFieldMaxExpansions($field, $maxExpansions);

		$expectedArray = array(
			'text' => array(
				$field => array(
					'query' => $queryText,
					'type' => $type,
					'analyzer' => $analyzer,
					'max_expansions' => $maxExpansions,
				)
			)
		);

		$this->assertEquals($expectedArray, $query->toArray());
	}