2 // $Id: search.views.inc,v 1.17 2009/02/23 23:30:38 merlinofchaos Exp $
5 * Provide views data and handlers for search.module
9 * @defgroup views_search_module search.module handlers
11 * Includes the tables 'search_index'
16 * Implementation of hook_views_data()
18 function search_views_data() {
19 // Basic table information.
21 // Define the base group of this table. Fields that don't
22 // have a group defined will go into this field by default.
23 $data['search_index']['table']['group'] = t('Search');
25 // For other base tables, explain how we join
26 $data['search_index']['table']['join'] = array(
28 'left_field' => 'nid',
32 'left_field' => 'uid',
37 $data['search_total']['table']['join'] = array(
39 'left_table' => 'search_index',
40 'left_field' => 'word',
44 'left_table' => 'search_index',
45 'left_field' => 'word',
50 $data['search_dataset']['table']['join'] = array(
52 'left_table' => 'search_index',
53 'left_field' => 'sid',
55 'extra' => 'search_index.type = search_dataset.type',
59 'left_table' => 'search_index',
60 'left_field' => 'sid',
62 'extra' => 'search_index.type = search_dataset.type',
67 // ----------------------------------------------------------------
71 $data['search_index']['score'] = array(
72 'title' => t('Score'),
73 'help' => t('The score of the search item. This will not be used if the search filter is not also present.'),
75 'handler' => 'views_handler_field_search_score',
76 'click sortable' => TRUE,
79 // Information for sorting on a search score.
81 'handler' => 'views_handler_sort_search_score',
85 // Search node links: forward links.
86 $data['search_node_links_from']['table']['group'] = t('Search');
87 $data['search_node_links_from']['table']['join'] = array(
89 'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
92 $data['search_node_links_from']['sid'] = array(
93 'title' => t('Links from'),
94 'help' => t('Other nodes that are linked from the node.'),
96 'handler' => 'views_handler_argument_node_nid',
99 'handler' => 'views_handler_filter_equality',
103 // Search node links: backlinks.
104 $data['search_node_links_to']['table']['group'] = t('Search');
105 $data['search_node_links_to']['table']['join'] = array(
107 'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
110 $data['search_node_links_to']['nid'] = array(
111 'title' => t('Links to'),
112 'help' => t('Other nodes that link to the node.'),
114 'handler' => 'views_handler_argument_node_nid',
117 'handler' => 'views_handler_filter_equality',
122 $data['search_index']['keys'] = array(
123 'title' => t('Search Terms'), // The item it appears as on the UI,
124 'help' => t('The terms to search for.'), // The help that appears on the UI,
125 // Information for searching terms using the full search syntax
127 'handler' => 'views_handler_filter_search',
135 * Implementation of hook_views_handlers() to register all of the basic handlers
138 function search_views_handlers() {
141 'path' => drupal_get_path('module', 'views') . '/modules/search',
144 'views_handler_field_search_score' => array(
145 'parent' => 'views_handler_field_numeric',
147 'views_handler_sort_search_score' => array(
148 'parent' => 'views_handler_sort',
150 'views_handler_filter_search' => array(
151 'parent' => 'views_handler_filter',
158 * Implementation of hook_views_plugins
160 function search_views_plugins() {
162 // DISABLED. This currently doesn't work.
164 'module' => 'views', // This just tells our themes are elsewhere.
167 'title' => t('Search'),
168 'help' => t('Display the results with standard search view.'),
169 'handler' => 'views_plugin_row_search_view',
170 'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules
171 'theme' => 'views_view_row_search',
172 'base' => array('node'), // only works with 'node' as base.
180 * Template helper for theme_views_view_row_search
182 function template_preprocess_views_view_row_search(&$vars) {
183 $vars['node'] = ''; // make sure var is defined.
184 $nid = $vars['row']->nid;
185 if (!is_numeric($nid)) {
189 $node = node_load($nid);
195 // Build the node body.
196 $node = node_build_content($node, FALSE, FALSE);
197 $node->body = drupal_render($node->content);
199 // Fetch comments for snippet
200 $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
202 // Fetch terms for snippet
203 $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
205 $vars['url'] = url('node/' . $nid);
206 $vars['title'] = check_plain($node->title);
209 $info['type'] = node_get_types('name', $node);
210 $info['user'] = theme('username', $node);
211 $info['date'] = format_date($node->changed, 'small');
212 $extra = node_invoke_nodeapi($node, 'search result');
213 if (isset($extra) && is_array($extra)) {
214 $info = array_merge($info, $extra);
216 $vars['info_split'] = $info;
217 $vars['info'] = implode(' - ', $info);
219 $vars['node'] = $node;
220 // @todo: get score from ???
221 //$vars['score'] = $item->score;
222 $vars['snippet'] = search_excerpt($vars['view']->value, $node->body);