Exemple #1
0
 public function testParse()
 {
     $data = array('responseHeader' => array('status' => 1, 'QTime' => 13), 'terms' => array('fieldA' => array('term1', 5, 'term2', 3), 'fieldB' => array('term3', 6, 'term4', 2)));
     $query = new Solarium_Query_Terms();
     $query->setFields('fieldA, fieldB');
     $resultStub = $this->getMock('Solarium_Result_Terms', array(), array(), '', false);
     $resultStub->expects($this->any())->method('getData')->will($this->returnValue($data));
     $resultStub->expects($this->any())->method('getQuery')->will($this->returnValue($query));
     $parser = new Solarium_Client_ResponseParser_Terms();
     $result = $parser->parse($resultStub);
     $expected = array('fieldA' => array('term1' => 5, 'term2' => 3), 'fieldB' => array('term3' => 6, 'term4' => 2));
     $this->assertEquals($expected, $result['results']);
     $this->assertEquals(2, count($result['results']));
 }
Exemple #2
0
 public function testBuildParams()
 {
     $this->_query->setFields('fieldA, fieldB');
     $this->_query->setLowerbound('d');
     $this->_query->setLowerboundInclude(true);
     $this->_query->setMinCount(3);
     $this->_query->setMaxCount(100);
     $this->_query->setPrefix('de');
     $this->_query->setRegex('det.*');
     $this->_query->setRegexFlags('case_insensitive,comments');
     $this->_query->setLimit(50);
     $this->_query->setUpperbound('x');
     $this->_query->setUpperboundInclude(false);
     $this->_query->setRaw(false);
     $this->_query->setSort('index');
     $request = $this->_builder->build($this->_query);
     $this->assertEquals(array('terms' => 'true', 'terms.fl' => array('fieldA', 'fieldB'), 'terms.limit' => 50, 'terms.lower' => 'd', 'terms.lower.incl' => 'true', 'terms.maxcount' => 100, 'terms.mincount' => 3, 'terms.prefix' => 'de', 'terms.raw' => 'false', 'terms.regex' => 'det.*', 'terms.regex.flag' => array('case_insensitive', 'comments'), 'terms.sort' => 'index', 'terms.upper' => 'x', 'terms.upper.incl' => 'false', 'wt' => 'json'), $request->getParams());
     $this->assertEquals(Solarium_Client_Request::METHOD_GET, $request->getMethod());
 }
Exemple #3
0
 public function testSetAndGetSort()
 {
     $this->_query->setSort('index');
     $this->assertEquals('index', $this->_query->getSort());
 }
Exemple #4
0
 /**
  * Build request for a Terms query
  *
  * @param Solarium_Query_Terms $query
  * @return Solarium_Client_Request
  */
 public function build($query)
 {
     $request = new Solarium_Client_Request();
     $request->setHandler($query->getHandler());
     $request->addParam('terms', true);
     $request->addParam('wt', 'json');
     $request->addParam('terms.lower', $query->getLowerbound());
     $request->addParam('terms.lower.incl', $query->getLowerboundInclude());
     $request->addParam('terms.mincount', $query->getMinCount());
     $request->addParam('terms.maxcount', $query->getMaxCount());
     $request->addParam('terms.prefix', $query->getPrefix());
     $request->addParam('terms.regex', $query->getRegex());
     $request->addParam('terms.limit', $query->getLimit());
     $request->addParam('terms.upper', $query->getUpperbound());
     $request->addParam('terms.upper.incl', $query->getUpperboundInclude());
     $request->addParam('terms.raw', $query->getRaw());
     $request->addParam('terms.sort', $query->getSort());
     $fields = explode(',', $query->getFields());
     foreach ($fields as $field) {
         $request->addParam('terms.fl', trim($field));
     }
     if ($query->getRegexFlags() !== null) {
         $flags = explode(',', $query->getRegexFlags());
         foreach ($flags as $flag) {
             $request->addParam('terms.regex.flag', trim($flag));
         }
     }
     return $request;
 }