| 1 |
<?php
|
| 2 |
// $Id: search.views.inc,v 1.17 2009/02/23 23:30:38 merlinofchaos Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provide views data and handlers for search.module
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* @defgroup views_search_module search.module handlers
|
| 10 |
*
|
| 11 |
* Includes the tables 'search_index'
|
| 12 |
* @{
|
| 13 |
*/
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_views_data()
|
| 17 |
*/
|
| 18 |
function search_views_data() {
|
| 19 |
// Basic table information.
|
| 20 |
|
| 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');
|
| 24 |
|
| 25 |
// For other base tables, explain how we join
|
| 26 |
$data['search_index']['table']['join'] = array(
|
| 27 |
'node' => array(
|
| 28 |
'left_field' => 'nid',
|
| 29 |
'field' => 'sid',
|
| 30 |
),
|
| 31 |
);
|
| 32 |
|
| 33 |
$data['search_total']['table']['join'] = array(
|
| 34 |
'node' => array(
|
| 35 |
'left_table' => 'search_index',
|
| 36 |
'left_field' => 'word',
|
| 37 |
'field' => 'word',
|
| 38 |
),
|
| 39 |
'users' => array(
|
| 40 |
'left_table' => 'search_index',
|
| 41 |
'left_field' => 'word',
|
| 42 |
'field' => 'word',
|
| 43 |
)
|
| 44 |
);
|
| 45 |
|
| 46 |
$data['search_dataset']['table']['join'] = array(
|
| 47 |
'node' => array(
|
| 48 |
'left_table' => 'search_index',
|
| 49 |
'left_field' => 'sid',
|
| 50 |
'field' => 'sid',
|
| 51 |
'extra' => 'search_index.type = search_dataset.type',
|
| 52 |
'type' => 'INNER',
|
| 53 |
),
|
| 54 |
'users' => array(
|
| 55 |
'left_table' => 'search_index',
|
| 56 |
'left_field' => 'sid',
|
| 57 |
'field' => 'sid',
|
| 58 |
'extra' => 'search_index.type = search_dataset.type',
|
| 59 |
'type' => 'INNER',
|
| 60 |
),
|
| 61 |
);
|
| 62 |
|
| 63 |
// ----------------------------------------------------------------
|
| 64 |
// Fields
|
| 65 |
|
| 66 |
// score
|
| 67 |
$data['search_index']['score'] = array(
|
| 68 |
'title' => t('Score'),
|
| 69 |
'help' => t('The score of the search item. This will not be used if the search filter is not also present.'),
|
| 70 |
'field' => array(
|
| 71 |
'handler' => 'views_handler_field_search_score',
|
| 72 |
'click sortable' => TRUE,
|
| 73 |
'float' => TRUE,
|
| 74 |
),
|
| 75 |
// Information for sorting on a search score.
|
| 76 |
'sort' => array(
|
| 77 |
'handler' => 'views_handler_sort_search_score',
|
| 78 |
),
|
| 79 |
);
|
| 80 |
|
| 81 |
// Search node links: forward links.
|
| 82 |
$data['search_node_links_from']['table']['group'] = t('Search');
|
| 83 |
$data['search_node_links_from']['table']['join'] = array(
|
| 84 |
'node' => array(
|
| 85 |
'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
|
| 86 |
),
|
| 87 |
);
|
| 88 |
$data['search_node_links_from']['sid'] = array(
|
| 89 |
'title' => t('Links from'),
|
| 90 |
'help' => t('Other nodes that are linked from the node.'),
|
| 91 |
'argument' => array(
|
| 92 |
'handler' => 'views_handler_argument_node_nid',
|
| 93 |
),
|
| 94 |
'filter' => array(
|
| 95 |
'handler' => 'views_handler_filter_equality',
|
| 96 |
),
|
| 97 |
);
|
| 98 |
|
| 99 |
// Search node links: backlinks.
|
| 100 |
$data['search_node_links_to']['table']['group'] = t('Search');
|
| 101 |
$data['search_node_links_to']['table']['join'] = array(
|
| 102 |
'node' => array(
|
| 103 |
'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
|
| 104 |
),
|
| 105 |
);
|
| 106 |
$data['search_node_links_to']['nid'] = array(
|
| 107 |
'title' => t('Links to'),
|
| 108 |
'help' => t('Other nodes that link to the node.'),
|
| 109 |
'argument' => array(
|
| 110 |
'handler' => 'views_handler_argument_node_nid',
|
| 111 |
),
|
| 112 |
'filter' => array(
|
| 113 |
'handler' => 'views_handler_filter_equality',
|
| 114 |
),
|
| 115 |
);
|
| 116 |
|
| 117 |
// search filter
|
| 118 |
$data['search_index']['keys'] = array(
|
| 119 |
'title' => t('Search Terms'), // The item it appears as on the UI,
|
| 120 |
'help' => t('The terms to search for.'), // The help that appears on the UI,
|
| 121 |
// Information for searching terms using the full search syntax
|
| 122 |
'filter' => array(
|
| 123 |
'handler' => 'views_handler_filter_search',
|
| 124 |
),
|
| 125 |
);
|
| 126 |
|
| 127 |
return $data;
|
| 128 |
}
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Implementation of hook_views_handlers() to register all of the basic handlers
|
| 132 |
* views uses.
|
| 133 |
*/
|
| 134 |
function search_views_handlers() {
|
| 135 |
return array(
|
| 136 |
'info' => array(
|
| 137 |
'path' => drupal_get_path('module', 'views') . '/modules/search',
|
| 138 |
),
|
| 139 |
'handlers' => array(
|
| 140 |
'views_handler_field_search_score' => array(
|
| 141 |
'parent' => 'views_handler_field_numeric',
|
| 142 |
),
|
| 143 |
'views_handler_sort_search_score' => array(
|
| 144 |
'parent' => 'views_handler_sort',
|
| 145 |
),
|
| 146 |
'views_handler_filter_search' => array(
|
| 147 |
'parent' => 'views_handler_filter',
|
| 148 |
),
|
| 149 |
),
|
| 150 |
);
|
| 151 |
}
|
| 152 |
|
| 153 |
/**
|
| 154 |
* Implementation of hook_views_plugins
|
| 155 |
*/
|
| 156 |
function search_views_plugins() {
|
| 157 |
return;
|
| 158 |
// DISABLED. This currently doesn't work.
|
| 159 |
return array(
|
| 160 |
'module' => 'views', // This just tells our themes are elsewhere.
|
| 161 |
'row' => array(
|
| 162 |
'search' => array(
|
| 163 |
'title' => t('Search'),
|
| 164 |
'help' => t('Display the results with standard search view.'),
|
| 165 |
'handler' => 'views_plugin_row_search_view',
|
| 166 |
'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules
|
| 167 |
'theme' => 'views_view_row_search',
|
| 168 |
'base' => array('node'), // only works with 'node' as base.
|
| 169 |
'type' => 'normal',
|
| 170 |
),
|
| 171 |
),
|
| 172 |
);
|
| 173 |
}
|
| 174 |
|
| 175 |
/**
|
| 176 |
* Template helper for theme_views_view_row_search
|
| 177 |
*/
|
| 178 |
function template_preprocess_views_view_row_search(&$vars) {
|
| 179 |
$vars['node'] = ''; // make sure var is defined.
|
| 180 |
$nid = $vars['row']->nid;
|
| 181 |
if (!is_numeric($nid)) {
|
| 182 |
return;
|
| 183 |
}
|
| 184 |
|
| 185 |
$node = node_load($nid);
|
| 186 |
|
| 187 |
if (empty($node)) {
|
| 188 |
return;
|
| 189 |
}
|
| 190 |
|
| 191 |
// Build the node body.
|
| 192 |
$node = node_build_content($node, FALSE, FALSE);
|
| 193 |
$node->body = drupal_render($node->content);
|
| 194 |
|
| 195 |
// Fetch comments for snippet
|
| 196 |
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
|
| 197 |
|
| 198 |
// Fetch terms for snippet
|
| 199 |
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
|
| 200 |
|
| 201 |
$vars['url'] = url('node/' . $nid);
|
| 202 |
$vars['title'] = check_plain($node->title);
|
| 203 |
|
| 204 |
$info = array();
|
| 205 |
$info['type'] = node_get_types('name', $node);
|
| 206 |
$info['user'] = theme('username', $node);
|
| 207 |
$info['date'] = format_date($node->changed, 'small');
|
| 208 |
$extra = node_invoke_nodeapi($node, 'search result');
|
| 209 |
if (isset($extra) && is_array($extra)) {
|
| 210 |
$info = array_merge($info, $extra);
|
| 211 |
}
|
| 212 |
$vars['info_split'] = $info;
|
| 213 |
$vars['info'] = implode(' - ', $info);
|
| 214 |
|
| 215 |
$vars['node'] = $node;
|
| 216 |
// @todo: get score from ???
|
| 217 |
//$vars['score'] = $item->score;
|
| 218 |
$vars['snippet'] = search_excerpt($vars['view']->value, $node->body);
|
| 219 |
}
|
| 220 |
|
| 221 |
|
| 222 |
/**
|
| 223 |
* @}
|
| 224 |
*/
|