/** * @group unit */ public function testSetScope() { $q = new MatchAll(); $type = 'test'; $scope = 'foo'; $query = new HasChild($q, $type); $query->setScope($scope); $expectedArray = array('has_child' => array('query' => $q->toArray(), 'type' => $type, '_scope' => $scope)); $this->assertEquals($expectedArray, $query->toArray()); }
/** * * @param BoolQuery $lead_query * @param AgentCriterion $criterion * * @return BoolQuery $lead_query */ protected function buildQuery(BoolQuery $lead_query, AgentCriterion $criterion) { if (!$criterion->getServiceLocator()) { $criterion->setServiceLocator($this->getServiceLocator()); } $criteria_query = false; $relationship = $criterion->getRelationship(); $required = $criterion->getRequired(); $weight = $criterion->getWeight(); if ($relationship) { $value = $criterion->getValue(); if ($value) { $data = $value->getData(); $boost = $weight ? (1 - $weight) * 10 + 1 : 1; $abstractQuery = $relationship->getQuery(); if ($abstractQuery) { $abstractQuery->setCriterion($criterion); $abstractQuery->setRelationship($relationship); $request = $this->getServiceLocator()->get('Request'); $debug = $request->getQuery('debug'); if ($debug) { echo "<script>console.dir(" . json_encode($data) . ");</script>\n"; } $boolQuery = $abstractQuery->getQuery($data, null, $required, $boost); if ($boolQuery) { switch ($relationship->getType()) { case 'location': $queryClass = (new \ReflectionClass($boolQuery))->getShortName(); switch ($queryClass) { case 'GeoDistance': $criteria_query = $boolQuery; break; default: $criteria_query = new Elastica\Query\HasChild($boolQuery, 'value'); $criteria_query->setParam('score_mode', 'avg'); break; } break; default: $criteria_query = new Elastica\Query\HasChild($boolQuery, 'value'); $criteria_query->setParam('score_mode', 'avg'); break; } if ($required) { $lead_query->addMust($criteria_query); } else { $lead_query->addShould($criteria_query); $lead_query->setBoost($boost); } } } } } return $lead_query; }