diff --git a/modules/search/views_handler_argument_search.inc b/modules/search/views_handler_argument_search.inc index f0a4a44..14e8bf3 100644 --- a/modules/search/views_handler_argument_search.inc +++ b/modules/search/views_handler_argument_search.inc @@ -13,6 +13,31 @@ class views_handler_argument_search extends views_handler_argument { /** + * Overrides views_handler_argument::option_definition(). + */ + function option_definition() { + $options = parent::option_definition(); + + $options['remove_score'] = array('default' => FALSE, 'bool' => TRUE); + + return $options; + } + + /** + * Overrides views_handler_argument::options_form(). + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['remove_score'] = array( + '#type' => 'checkbox', + '#title' => t('Remove search score'), + '#description' => t('Check this box to remove the search score from the query. This can help reduce help reduce duplicate search results when using this filter.'), + '#default_value' => $this->options['remove_score'], + ); + } + + /** * Take sure that parseSearchExpression is runned and everything is set up for it. * * @param $input @@ -51,12 +76,14 @@ class views_handler_argument_search extends views_handler_argument { $search_condition = db_and(); - // Create a new join to relate the 'search_total' table to our current 'search_index' table. - $join = new views_join; - $join->construct('search_total', $search_index, 'word', 'word'); - $search_total = $this->query->add_relationship('search_total', $join, $search_index); + if (!$this->options['remove_score']) { + // Create a new join to relate the 'search_total' table to our current 'search_index' table. + $join = new views_join; + $join->construct('search_total', $search_index, 'word', 'word'); + $search_total = $this->query->add_relationship('search_total', $join, $search_index); - $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); + $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); + } if (empty($this->query->relationships[$this->relationship])) { $base_table = $this->query->base_table;