? 362830-search-score-totally-broken.patch ? 373760-fix-aggregate.patch ? 378534-1.arg_validator_wildcard_php_sucks.patch ? TODO.txt ? api.txt ? book.txt ? distinct_followup.patch ? doc ? get_all_views_reset_static.patch ? test.php ? views-help-typos.patch ? views-list-css-rtl2.patch ? views_taxo_filter_exposed.patch Index: includes/query.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/query.inc,v retrieving revision 1.39 diff -u -p -r1.39 query.inc --- includes/query.inc 20 Feb 2009 20:37:59 -0000 1.39 +++ includes/query.inc 20 Feb 2009 22:40:48 -0000 @@ -773,9 +773,7 @@ class views_query { } /** - * Add multiple an orderby's. Right now I'm not sure why this function - * is separate from add_orderby above; I don't think it needs to - * be. + * Add an ORDER BY clause to the query. * * @param $table * The table this field is part of. If a formula, enter NULL. @@ -824,7 +822,7 @@ class views_query { * added. */ function add_groupby($clause) { - // Only add it if it's already in there. + // Only add it if it's not already in there. if (!in_array($clause, $this->groupby)) { $this->groupby[] = $clause; } Index: modules/search.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/search.views.inc,v retrieving revision 1.15 diff -u -p -r1.15 search.views.inc --- modules/search.views.inc 2 Dec 2008 19:37:08 -0000 1.15 +++ modules/search.views.inc 20 Feb 2009 22:40:48 -0000 @@ -75,12 +75,12 @@ function search_views_data() { 'field' => array( 'field' => 'score', // the real field 'group' => t('Search'), // The group it appears in on the UI, - 'handler' => 'views_handler_field', + 'handler' => 'views_handler_field_search_score', 'click sortable' => TRUE, ), // Information for sorting on a search score. 'sort' => array( - 'handler' => 'views_handler_sort', + 'handler' => 'views_handler_sort_search_score', ), ); @@ -143,6 +143,12 @@ function search_views_handlers() { 'path' => drupal_get_path('module', 'views') . '/modules/search', ), 'handlers' => array( + 'views_handler_field_search_score' => array( + 'parent' => 'views_handler_field_numeric', + ), + 'views_handler_sort_search_score' => array( + 'parent' => 'views_handler_sort', + ), 'views_handler_filter_search' => array( 'parent' => 'views_handler_filter', ), Index: modules/search/views_handler_field_search_score.inc =================================================================== RCS file: modules/search/views_handler_field_search_score.inc diff -N modules/search/views_handler_field_search_score.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/search/views_handler_field_search_score.inc 20 Feb 2009 22:40:48 -0000 @@ -0,0 +1,24 @@ +search_score -- and we also + // need to check its relationship to make sure that we're using the same + // one or obviously this won't work. + foreach ($this->view->filter as $handler) { + if (isset($handler->search_score) && $handler->relationship == $this->relationship) { + $this->field_alias = $handler->search_score; + $this->table_alias = $handler->table_alias; + return; + } + } + + // Fallback to normal operation if the above didn't find anything: + return parent::query(); + } +} Index: modules/search/views_handler_filter_search.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/search/views_handler_filter_search.inc,v retrieving revision 1.3 diff -u -p -r1.3 views_handler_filter_search.inc --- modules/search/views_handler_filter_search.inc 20 Feb 2009 20:35:37 -0000 1.3 +++ modules/search/views_handler_filter_search.inc 20 Feb 2009 22:40:48 -0000 @@ -55,8 +55,6 @@ class views_handler_filter_search extend $key = $this->options['expose']['identifier']; if (!empty($form_state['values'][$key])) { $this->search_query = search_parse_query($form_state['values'][$key]); - $this->search_query[0] = str_replace('d.', 'search_dataset.', $this->search_query[0]); - $this->search_query[2] = str_replace('i.', 'search_index.', $this->search_query[2]); if ($this->search_query[2] == '') { form_set_error($key, t('You must include at least one positive keyword with @count characters or more.', array('@count' => variable_get('minimum_word_size', 3)))); @@ -83,22 +81,33 @@ class views_handler_filter_search extend } } else { - $this->ensure_my_table(); + $search_index = $this->ensure_my_table(); + $this->search_query[2] = str_replace('i.', "$search_index.", $this->search_query[2]); + + // Create a new join to relate the 'serach_total' table to our current 'search_index' table. $join = new views_join; - $join->construct('search_total', 'search_index', 'word', 'word'); - $this->query->add_relationship(NULL, $join, 'search_index'); -// $this->query->add_table('search_total', 'search_index', $join); - $this->query->add_field('', "SUM(search_index.score * search_total.count)", 'score', array('aggregate' => TRUE)); + $join->construct('search_total', $search_index, 'word', 'word'); + $search_total = $this->query->add_relationship(NULL, $join, $search_index); + + $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); + $this->query->add_where($this->options['group'], $this->search_query[2], $this->search_query[3]); - $this->query->add_where($this->options['group'], "search_index.type = '%s'", $this->view->base_table); + + if (empty($this->query->relationships[$this->relationship])) { + $base_table = $this->query->base_table; + } + else { + $base_table = $this->query->relationships[$this->relationship]['base']; + } + $this->query->add_where($this->options['group'], "$search_index.type = '%s'", $base_table); if (!$this->search_query[5]) { - $this->query->add_table('search_dataset'); + $search_dataset = $this->query->add_table('search_dataset'); + $this->search_query[0] = str_replace('d.', "$search_dataset.", $this->search_query[0]); $this->query->add_where($this->options['group'], $this->search_query[0], $this->search_query[1]); } - // @note: i don't think that this needed since we restrict based on type - $this->query->add_groupby("search_index.sid"); + + $this->query->add_groupby("$search_index.sid"); $this->query->add_having($this->options['group'], 'COUNT(*) >= %d', $this->search_query[4]); - // @todo: normalize the score } } } Index: modules/search/views_handler_sort_search_score.inc =================================================================== RCS file: modules/search/views_handler_sort_search_score.inc diff -N modules/search/views_handler_sort_search_score.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/search/views_handler_sort_search_score.inc 20 Feb 2009 22:40:48 -0000 @@ -0,0 +1,25 @@ +search_score -- and we also + // need to check its relationship to make sure that we're using the same + // one or obviously this won't work. + foreach ($this->view->filter as $handler) { + if (isset($handler->search_score) && $handler->relationship == $this->relationship) { + $this->query->add_orderby(NULL, NULL, $this->options['order'], $handler->search_score); + $this->table_alias = $handler->table_alias; + return; + } + } + + // Fallback to normal operation if the above didn't find anything: + return parent::query(); + } +} +