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