You are here

class similar_handler_filter_similarity in Similar Entries 6.2

Same name and namespace in other branches
  1. 7.2 views/similar_handler_filter_similarity.inc \similar_handler_filter_similarity

Defines the score filter handler.

Hierarchy

Expanded class hierarchy of similar_handler_filter_similarity

1 string reference to 'similar_handler_filter_similarity'
similar_views_data in views/similar.views.inc
Implements hook_views_data().

File

views/similar_handler_filter_similarity.inc, line 11
Defines the score filter handler for Similar entries module.

View source
class similar_handler_filter_similarity extends views_handler_filter_numeric {

  /**
   * Defines default values for the operator and value.
   */
  public function option_definition() {
    $options = parent::option_definition();
    $options['operator'] = array(
      'default' => '>',
    );
    $options['value'] = array(
      'default' => '1',
    );
    return $options;
  }

  /**
   * Alters the settings form to make the value a select list instead of text.
   */
  public function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $this
      ->show_operator_form($form, $form_state);

    // The between/not between operators don't make sense for relevance.
    unset($form['operator']['#options']['between'], $form['operator']['#options']['not between']);
    $form['value']['#type'] = 'select';
    $form['value']['#description'] = t('Choosing a higher number will further limit the amount of results and provide only results with a higher similarity rating.');
    $form['value']['#options'] = array(
      '0',
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      '9',
      '10',
    );
    $form['value']['#default_value'] = $this->value;
  }

  /**
   * Inserts a having clause into the query.
   */
  public function query() {
    $this
      ->ensure_my_table();
    $this->query
      ->add_having('nid', "score {$this->operator} (%d)", $this->value);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
similar_handler_filter_similarity::options_form public function Alters the settings form to make the value a select list instead of text.
similar_handler_filter_similarity::option_definition public function Defines default values for the operator and value.
similar_handler_filter_similarity::query public function Inserts a having clause into the query.