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()); }
/** * @param string[] $fields * @param string[] $nearMatchFields * @param string $queryString * @param string $nearMatchQuery * @return \Elastica\Query\Simple|\Elastica\Query\Bool */ private function buildSearchTextQuery(array $fields, array $nearMatchFields, $queryString, $nearMatchQuery) { $queryForMostFields = $this->buildSearchTextQueryForFields($fields, $queryString, $this->config->getElement('CirrusSearchPhraseSlop', 'default'), false); if ($nearMatchQuery) { // Build one query for the full text fields and one for the near match fields so that // the near match can run unescaped. $bool = new \Elastica\Query\Bool(); $bool->setMinimumNumberShouldMatch(1); $bool->addShould($queryForMostFields); $nearMatch = new \Elastica\Query\MultiMatch(); $nearMatch->setFields($nearMatchFields); $nearMatch->setQuery($nearMatchQuery); $bool->addShould($nearMatch); return $bool; } return $queryForMostFields; }