Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function compare(Address $a, Address $b, $geocoderQuery)
 {
     $aContains = $this->queryContainsCity($a, $geocoderQuery);
     $bContains = $this->queryContainsCity($b, $geocoderQuery);
     if ($aContains && $bContains) {
         return $this->fallback ? $this->fallback->compare($a, $b, $geocoderQuery) : 0;
     } elseif ($aContains) {
         return -1;
     } elseif ($bContains) {
         return 1;
     }
     $aP = $bP = PHP_INT_MAX;
     foreach ($this->cityPriority as $city => $priority) {
         if (preg_match('~' . $city . '~i', trim($a->getLocality())) && $priority < $aP) {
             $aP = $priority;
         }
         if (preg_match('~' . $city . '~i', trim($b->getLocality())) && $priority < $bP) {
             $bP = $priority;
         }
     }
     if ($aP == $bP) {
         return $this->fallback ? $this->fallback->compare($a, $b, $geocoderQuery) : 0;
     }
     return $aP < $bP ? -1 : 1;
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function compare(Address $a, Address $b, $geocoderQuery)
 {
     $aL = (int) levenshtein($this->formatSimpleFull($a), $geocoderQuery);
     $bL = (int) levenshtein($this->formatSimpleFull($b), $geocoderQuery);
     if ($aL == $bL) {
         return $this->fallback ? $this->fallback->compare($a, $b, $geocoderQuery) : 0;
     }
     return $aL > $bL ? 1 : -1;
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function geocode($value)
 {
     $allAddresses = $this->provider->limit($this->getLimit())->geocode($value)->all();
     @uasort($allAddresses, function (Address $a, Address $b) use($value) {
         return $this->comparator->compare($a, $b, $value);
     });
     // intentionally, usorts cries when compared objects are modified
     return new AddressCollection($allAddresses);
 }
Пример #4
0
 /**
  * {@inheritDoc}
  */
 public function geocode($value)
 {
     $allAddresses = [];
     foreach ($this->aggregator->getProviders() as $provider) {
         $allAddresses = array_merge($allAddresses, $provider->geocode($value)->all());
     }
     @uasort($allAddresses, function (Address $a, Address $b) use($value) {
         return $this->comparator->compare($a, $b, $value);
     });
     // intentionally, usorts cries when compared objects are modified
     return new AddressCollection(array_slice($allAddresses, 0, $this->getLimit()));
 }
Пример #5
0
 /**
  * {@inheritDoc}
  */
 public function compare(Address $a, Address $b, $query)
 {
     if (($compareCity = $this->compareCity($a, $b, $query)) !== 0) {
         return $compareCity;
     }
     if (($compareStreets = $this->compareStreet($a, $b, $query)) !== 0) {
         return $compareStreets;
     }
     if (($compareNumbers = $this->compareNumbers($a, $b, $query)) !== 0) {
         return $compareNumbers;
     }
     return $this->fallback ? $this->fallback->compare($a, $b, $query) : 0;
 }