Ejemplo n.º 1
0
 /**
  * Test to resolve the following issue
  *
  * https://groups.google.com/forum/?fromgroups#!topic/elastica-php-client/zK_W_hClfvU
  */
 public function testToArrayStructure()
 {
     $boolQuery = new Elastica_Query_Bool();
     $term1 = new Elastica_Query_Term();
     $term1->setParam('interests', 84);
     $term2 = new Elastica_Query_Term();
     $term2->setParam('interests', 92);
     $boolQuery->addShould($term1)->addShould($term2);
     $jsonString = '{"bool":{"should":[{"term":{"interests":84}},{"term":{"interests":92}}]}}';
     $this->assertEquals($jsonString, json_encode($boolQuery->toArray()));
 }
Ejemplo n.º 2
0
 public function testToArray()
 {
     $query = new Elastica_Query_Bool();
     $idsQuery1 = new Elastica_Query_Ids();
     $idsQuery1->setIds(1);
     $idsQuery2 = new Elastica_Query_Ids();
     $idsQuery2->setIds(2);
     $idsQuery3 = new Elastica_Query_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());
 }