toArray() public method

Converts filter to array.
See also: Elastica\Query\AbstractQuery::toArray()
public toArray ( ) : array
return array Query array
示例#1
0
 /**
  * @group unit
  */
 public function testToArray()
 {
     $query = new BoolQuery();
     $idsQuery1 = new Ids();
     $idsQuery1->setIds(1);
     $idsQuery2 = new Ids();
     $idsQuery2->setIds(2);
     $idsQuery3 = new Ids();
     $idsQuery3->setIds(3);
     $filter1 = new TermFilter();
     $filter1->setTerm('test', '1');
     $filter2 = new TermFilter();
     $filter2->setTerm('username', 'ruth');
     $boost = 1.2;
     $minMatch = 2;
     $query->setBoost($boost);
     $query->setMinimumNumberShouldMatch($minMatch);
     $query->addMust($idsQuery1);
     $query->addMustNot($idsQuery2);
     $query->addShould($idsQuery3->toArray());
     $query->addFilter($filter1);
     $query->addFilter($filter2);
     $expectedArray = array('bool' => array('must' => array($idsQuery1->toArray()), 'should' => array($idsQuery3->toArray()), 'filter' => array($filter1->toArray(), $filter2->toArray()), 'minimum_number_should_match' => $minMatch, 'must_not' => array($idsQuery2->toArray()), 'boost' => $boost));
     $this->assertEquals($expectedArray, $query->toArray());
 }
示例#2
0
 /**
  * @group unit
  */
 public function testToArray()
 {
     $query = new DisMax();
     $idsQuery1 = new Ids();
     $idsQuery1->setIds(1);
     $idsQuery2 = new Ids();
     $idsQuery2->setIds(2);
     $idsQuery3 = new Ids();
     $idsQuery3->setIds(3);
     $boost = 1.2;
     $tieBreaker = 2;
     $query->setBoost($boost);
     $query->setTieBreaker($tieBreaker);
     $query->addQuery($idsQuery1);
     $query->addQuery($idsQuery2);
     $query->addQuery($idsQuery3->toArray());
     $expectedArray = array('dis_max' => array('tie_breaker' => $tieBreaker, 'boost' => $boost, 'queries' => array($idsQuery1->toArray(), $idsQuery2->toArray(), $idsQuery3->toArray())));
     $this->assertEquals($expectedArray, $query->toArray());
 }
 public function testToArray()
 {
     $query = new Bool();
     $idsQuery1 = new Ids();
     $idsQuery1->setIds(1);
     $idsQuery2 = new Ids();
     $idsQuery2->setIds(2);
     $idsQuery3 = new Ids();
     $idsQuery3->setIds(3);
     $boost = 1.2;
     $minMatch = 2;
     $query->setBoost($boost);
     $query->setMinimumNumberShouldMatch($minMatch);
     $query->addMust($idsQuery1);
     $query->addMustNot($idsQuery2);
     $query->addShould($idsQuery3->toArray());
     $expectedArray = array('bool' => array('must' => array($idsQuery1->toArray()), 'should' => array($idsQuery3->toArray()), 'minimum_number_should_match' => $minMatch, 'must_not' => array($idsQuery2->toArray()), 'boost' => $boost));
     $this->assertEquals($expectedArray, $query->toArray());
 }