コード例 #1
0
 /**
  *
  * @param \Agent\Entity\AgentCriterion $criterion        	
  *
  * @return AbstractQuery
  */
 public function setCriterion($criterion)
 {
     if ($criterion) {
         $relationship = $criterion->getRelationship();
         if ($relationship) {
             $this->setRelationship($relationship);
         }
     } else {
         $this->setRelationship(null);
     }
     $this->criterion = $criterion;
     return $this;
 }
コード例 #2
0
 /**
  *
  * @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;
 }