Example #1
0
 /** @brief Creates new interval helper from string.
  *
  * @param $value [in] String value to parse in order to create new
  *        AfsInterval instance.
  *
  * @return newly created instance.
  */
 public static function parse($value)
 {
     $bound_pattern = '([0-9."-]+)';
     $sign_pattern = '(\\[|\\])';
     $interval_pattern = '/^' . $sign_pattern . $bound_pattern . ' .. ' . $bound_pattern . $sign_pattern . '$/';
     $matches = array();
     $result = preg_match($interval_pattern, $value, $matches);
     if (1 == $result) {
         if (count($matches) != 5) {
             throw new Exception('Invalid number of matching elements, please contact Antidot support team');
         }
         $interval = new AfsInterval($matches[2], $matches[3]);
         if (']' == $matches[1]) {
             $interval->exclude_lower_bound();
         }
         if ('[' == $matches[4]) {
             $interval->exclude_upper_bound();
         }
         return $interval;
     } elseif (0 == $result) {
         throw new AfsIntervalInitializerException($value);
     } else {
         throw new Exception('Please contact Antidot support for this PHP API!');
     }
 }
Example #2
0
 public function testBuildIntervalFromInvalidStringValue()
 {
     try {
         AfsInterval::parse('[10..20]');
         $this->fail('Invalid interval string should have not been parsed!');
     } catch (AfsIntervalInitializerException $e) {
     }
     try {
         AfsInterval::parse('10 .. 20]');
         $this->fail('Invalid interval string should have not been parsed!');
     } catch (AfsIntervalInitializerException $e) {
     }
     try {
         AfsInterval::parse('[10 .. 20');
         $this->fail('Invalid interval string should have not been parsed!');
     } catch (AfsIntervalInitializerException $e) {
     }
     try {
         AfsInterval::parse('[10 . 20]');
         $this->fail('Invalid interval string should have not been parsed!');
     } catch (AfsIntervalInitializerException $e) {
     }
 }
Example #3
0
 public function testSetIntervalValueToFilter()
 {
     $query = new AfsQuery();
     $query = $query->set_filter('foo', AfsInterval::create(42, 666));
     $this->assertTrue($query->has_filter('foo', '[42 .. 666]'));
 }
 public function testOneFacetOneIntervalValue()
 {
     $query = new AfsQuery();
     $query = $query->add_filter('foo', AfsInterval::create(42, 666));
     $this->qm->send($query);
     $this->checkOneFacetValue('foo', '[42 .. 666]');
 }