public function executeSearch(sfWebRequest $request) { $term = strtolower($request->getParameter('q')); $this->q = $term; $transport = new ElasticSearchTransportHTTP('localhost', 9200); $search = new ElasticSearchClient($transport, "cotinga", "item"); $dsl = array('facets' => array('subjects' => array('terms' => array('field' => 'dc.subject.untouched', 'size' => 10)), 'types' => array('terms' => array('field' => 'dc.type', 'size' => 5)), 'language' => array('terms' => array('field' => 'dc.language.iso.untouched', 'size' => 10)), 'creator' => array('terms' => array('field' => 'dc.creator.untouched', 'size' => 10))), 'size' => 50); $filterSubject = $request->getParameter('filters'); if ($filterSubject) { $dsl['query'] = array('filtered' => array('query' => array('dis_max' => array('queries' => array(0 => array('term' => array('dc.title' => $term)), 1 => array('prefix' => array('dc.title' => $term)), 2 => array('prefix' => array('dc.subject' => $term))))))); $values = array(); foreach ($filterSubject as $subject) { foreach ($subject as $field => $value) { $values[] = $value; } } $dsl['query']['filtered']['filter'] = array('query' => array('field' => array('dc.subject' => implode(' AND ', $values)))); } else { $dsl['query'] = array('dis_max' => array('queries' => array(0 => array('term' => array('dc.title' => $term)), 1 => array('prefix' => array('dc.title' => $term)), 2 => array('prefix' => array('dc.subject' => $term)), 3 => array('term' => array('dc.description.abstract' => $term))))); } $this->dsl = $dsl; $results = $search->search($dsl); $this->results = $results; }
/** * @expectedException ElasticSearchTransportHTTPException */ public function testSearchThrowExceptionWhenServerDown() { $transport = new ElasticSearchTransportHTTP("localhost", 9300); $search = new ElasticSearchClient($transport, "test-index", "test-type"); $search->search("title:cool"); }