Example #1
0
 /**
  * Add a limit
  * 
  * @param string $boolean	boolean combine type
  * @param string $field		field name
  * @param string $relation	operator
  * @param string $phrase	the value of the limit
  * 
  * @return boolean          true if successful, false if limit not supported
  */
 public function addLimit($boolean, $field, $relation, $phrase)
 {
     $term = new LimitTerm();
     $term->boolean = $boolean;
     $term->field = $field;
     $term->relation = $relation;
     $term->value = $phrase;
     if ($boolean == 'NOT') {
         $term->param = str_replace('facet.', 'facet.remove.', $field);
     } else {
         $term->param = $field;
     }
     // take the field name out of our facet.* param
     if (strstr($term->field, "facet.")) {
         $parts = explode('.', $term->field);
         // if it has 3 parts, it's our special 'key' convention, where
         // the third part is the value, so swap it in for the value
         if (count($parts) == 3) {
             $term->value = array_pop($parts);
             $term->field = array_pop($parts);
             $term->key = true;
             $term->display = $phrase;
             // @todo: make this not 'display'
         } else {
             // the field name is the only thing there, value is already
             // populated in the value of the limit object
             $term->field = array_pop($parts);
         }
     }
     // see if this field is supported by the config
     if ($this->config != null) {
         if ($this->config->getFacet($term->field) == null && $this->config->getLimit($term->field) == null) {
             return false;
             // nope
         }
     }
     array_push($this->limits, $term);
     return true;
 }