Projet

Général

Profil

Paste
Télécharger (5,83 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / search.views.inc @ 5d12d676

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
  // Define the base group of this table. Fields that don't have a group
16
  // defined will go into this field by default.
17
  $data['search_index']['table']['group']  = t('Search');
18

    
19
  // For other base tables, explain how we join.
20
  $data['search_index']['table']['join'] = array(
21
    'node' => array(
22
      'left_field' => 'nid',
23
      'field' => 'sid',
24
    ),
25
  );
26

    
27
  $data['search_total']['table']['join'] = array(
28
    'node' => array(
29
      'left_table' => 'search_index',
30
      'left_field' => 'word',
31
      'field' => 'word',
32
    ),
33
    'users' => array(
34
      'left_table' => 'search_index',
35
      'left_field' => 'word',
36
      'field' => 'word',
37
    ),
38
  );
39

    
40
  $data['search_dataset']['table']['join'] = array(
41
    'node' => array(
42
      'left_table' => 'search_index',
43
      'left_field' => 'sid',
44
      'field' => 'sid',
45
      'extra' => array('search_index.type = search_dataset.type'),
46
      'type' => 'INNER',
47
    ),
48
    'users' => array(
49
      'left_table' => 'search_index',
50
      'left_field' => 'sid',
51
      'field' => 'sid',
52
      'extra' => array('search_index.type = search_dataset.type'),
53
      'type' => 'INNER',
54
    ),
55
  );
56

    
57
  // ----------------------------------------------------------------
58
  // Fields.
59
  // Score.
60
  $data['search_index']['score'] = array(
61
    'title' => t('Score'),
62
    'help' => t('The score of the search item. This will not be used if the search filter is not also present.'),
63
    'field' => array(
64
      'handler' => 'views_handler_field_search_score',
65
      'click sortable' => TRUE,
66
      'float' => TRUE,
67
      'no group by' => TRUE,
68
    ),
69
    // Information for sorting on a search score.
70
    'sort' => array(
71
      'handler' => 'views_handler_sort_search_score',
72
      'no group by' => TRUE,
73
    ),
74
  );
75

    
76
  // Search node links: forward links.
77
  $data['search_node_links_from']['table']['group'] = t('Search');
78
  $data['search_node_links_from']['table']['join'] = array(
79
    'node' => array(
80
      'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
81
    ),
82
  );
83
  $data['search_node_links_from']['sid'] = array(
84
    'title' => t('Links from'),
85
    'help' => t('Other nodes that are linked from the node.'),
86
    'argument' => array(
87
      'handler' => 'views_handler_argument_node_nid',
88
    ),
89
    'filter' => array(
90
      'handler' => 'views_handler_filter_equality',
91
    ),
92
  );
93

    
94
  // Search node links: backlinks.
95
  $data['search_node_links_to']['table']['group'] = t('Search');
96
  $data['search_node_links_to']['table']['join'] = array(
97
    'node' => array(
98
      'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
99
    ),
100
  );
101
  $data['search_node_links_to']['nid'] = array(
102
    'title' => t('Links to'),
103
    'help' => t('Other nodes that link to the node.'),
104
    'argument' => array(
105
      'handler' => 'views_handler_argument_node_nid',
106
    ),
107
    'filter' => array(
108
      'handler' => 'views_handler_filter_equality',
109
    ),
110
  );
111

    
112
  // Search filter.
113
  $data['search_index']['keys'] = array(
114
    // The item it appears as on the UI,
115
    'title' => t('Search Terms'),
116
    // The help that appears on the UI,
117
    'help' => t('The terms to search for.'),
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
  // @todo Fix this.
139
  return array(
140
    'module' => 'views',
141
    // This just tells our themes are elsewhere.
142
    'row' => array(
143
      'search' => array(
144
        'title' => t('Search'),
145
        'help' => t('Display the results with standard search view.'),
146
        'handler' => 'views_plugin_row_search_view',
147
        'theme' => 'views_view_row_search',
148
        'path' => drupal_get_path('module', 'views') . '/modules/search',
149
        // Not necessary for most modules.
150
        'base' => array('node'),
151
        // Only works with 'node' as base.
152
        'type' => 'normal',
153
      ),
154
      'views_handler_argument_search' => array(
155
        'parent' => 'views_handler_argument',
156
      ),
157
    ),
158
  );
159
}
160

    
161
/**
162
 * Template helper for theme_views_view_row_search.
163
 */
164
function template_preprocess_views_view_row_search(&$vars) {
165
  $vars['node'] = '';
166
  // Make sure var is defined.
167
  $nid = $vars['row']->nid;
168
  if (!is_numeric($nid)) {
169
    return;
170
  }
171

    
172
  // @todo Once the search row is fixed this node_load should be replace by a
173
  // node_load_multiple().
174
  $node = node_load($nid);
175

    
176
  if (empty($node)) {
177
    return;
178
  }
179

    
180
  // Build the node body.
181
  $node = node_build_content($node, FALSE, FALSE);
182
  $node->body = drupal_render($node->content);
183

    
184
  // Fetch comments for snippet.
185
  $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
186

    
187
  // Fetch terms for snippet.
188
  $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
189

    
190
  $vars['url'] = url('node/' . $nid);
191
  $vars['title'] = check_plain($node->title);
192

    
193
  $info = array();
194
  $info['type'] = node_type_get_name($node);
195
  $info['user'] = theme('username', array('acccount' => $node));
196
  $info['date'] = format_date($node->changed, 'small');
197
  $extra = module_invoke_all('node_search_result', $node);
198
  if (isset($extra) && is_array($extra)) {
199
    $info = array_merge($info, $extra);
200
  }
201
  $vars['info_split'] = $info;
202
  $vars['info'] = implode(' - ', $info);
203

    
204
  $vars['node'] = $node;
205
  // @todo Where does the score come from?
206
  // $vars['score'] = $item->score;
207
  $vars['snippet'] = search_excerpt($vars['view']->value, $node->body);
208
}