• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/search.views.inc

Go to the documentation of this file.
00001 <?php
00017 function search_views_data() {
00018   // Basic table information.
00019 
00020   // Define the base group of this table. Fields that don't
00021   // have a group defined will go into this field by default.
00022   $data['search_index']['table']['group']  = t('Search');
00023 
00024   // For other base tables, explain how we join
00025   $data['search_index']['table']['join'] = array(
00026     'node' => array(
00027       'left_field' => 'nid',
00028       'field' => 'sid',
00029     ),
00030   );
00031 
00032   $data['search_total']['table']['join'] = array(
00033     'node' => array(
00034       'left_table' => 'search_index',
00035       'left_field' => 'word',
00036       'field' => 'word',
00037     ),
00038     'users' => array(
00039       'left_table' => 'search_index',
00040       'left_field' => 'word',
00041       'field' => 'word',
00042     )
00043   );
00044 
00045   $data['search_dataset']['table']['join'] = array(
00046     'node' => array(
00047       'left_table' => 'search_index',
00048       'left_field' => 'sid',
00049       'field' => 'sid',
00050       'extra' => 'search_index.type = search_dataset.type',
00051       'type' => 'INNER',
00052     ),
00053     'users' => array(
00054       'left_table' => 'search_index',
00055       'left_field' => 'sid',
00056       'field' => 'sid',
00057       'extra' => 'search_index.type = search_dataset.type',
00058       'type' => 'INNER',
00059     ),
00060   );
00061 
00062   // ----------------------------------------------------------------
00063   // Fields
00064 
00065   // score
00066   $data['search_index']['score'] = array(
00067     'title' => t('Score'),
00068     'help' => t('The score of the search item. This will not be used if the search filter is not also present.'),
00069     'field' => array(
00070       'handler' => 'views_handler_field_search_score',
00071       'click sortable' => TRUE,
00072       'float' => TRUE,
00073       'no group by' => TRUE,
00074     ),
00075     // Information for sorting on a search score.
00076     'sort' => array(
00077       'handler' => 'views_handler_sort_search_score',
00078       'no group by' => TRUE,
00079     ),
00080   );
00081 
00082   // Search node links: forward links.
00083   $data['search_node_links_from']['table']['group'] = t('Search');
00084   $data['search_node_links_from']['table']['join'] = array(
00085     'node' => array(
00086       'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
00087     ),
00088   );
00089   $data['search_node_links_from']['sid'] = array(
00090     'title' => t('Links from'),
00091     'help' => t('Other nodes that are linked from the node.'),
00092     'argument' => array(
00093       'handler' => 'views_handler_argument_node_nid',
00094     ),
00095     'filter' => array(
00096       'handler' => 'views_handler_filter_equality',
00097     ),
00098   );
00099 
00100   // Search node links: backlinks.
00101   $data['search_node_links_to']['table']['group'] = t('Search');
00102   $data['search_node_links_to']['table']['join'] = array(
00103     'node' => array(
00104       'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
00105     ),
00106   );
00107   $data['search_node_links_to']['nid'] = array(
00108     'title' => t('Links to'),
00109     'help' => t('Other nodes that link to the node.'),
00110     'argument' => array(
00111       'handler' => 'views_handler_argument_node_nid',
00112     ),
00113     'filter' => array(
00114       'handler' => 'views_handler_filter_equality',
00115     ),
00116   );
00117 
00118   // search filter
00119   $data['search_index']['keys'] = array(
00120     'title' => t('Search Terms'), // The item it appears as on the UI,
00121     'help' => t('The terms to search for.'), // The help that appears on the UI,
00122     // Information for searching terms using the full search syntax
00123     'filter' => array(
00124       'handler' => 'views_handler_filter_search',
00125       'no group by' => TRUE,
00126     ),
00127     'argument' => array(
00128       'handler' => 'views_handler_argument_search',
00129       'no group by' => TRUE,
00130     ),
00131   );
00132 
00133   return $data;
00134 }
00135 
00139 function search_views_plugins() {
00140   return;
00141   // DISABLED. This currently doesn't work.
00142   return array(
00143     'module' => 'views', // This just tells our themes are elsewhere.
00144     'row' => array(
00145       'search' => array(
00146         'title' => t('Search'),
00147         'help' => t('Display the results with standard search view.'),
00148         'handler' => 'views_plugin_row_search_view',
00149         'theme' => 'views_view_row_search',
00150         'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules
00151         'base' => array('node'), // only works with 'node' as base.
00152         'type' => 'normal',
00153       ),
00154       'views_handler_argument_search' => array(
00155         'parent' => 'views_handler_argument',
00156       ),
00157     ),
00158   );
00159 }
00160 
00164 function template_preprocess_views_view_row_search(&$vars) {
00165   $vars['node'] = ''; // make sure var is defined.
00166   $nid = $vars['row']->nid;
00167   if (!is_numeric($nid)) {
00168     return;
00169   }
00170 
00171   // @todo: Once the search row is fixed this node_load should be replace by a node_load_multiple
00172   $node = node_load($nid);
00173 
00174   if (empty($node)) {
00175     return;
00176   }
00177 
00178   // Build the node body.
00179   $node = node_build_content($node, FALSE, FALSE);
00180   $node->body = drupal_render($node->content);
00181 
00182   // Fetch comments for snippet
00183   $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
00184 
00185   // Fetch terms for snippet
00186   $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
00187 
00188   $vars['url'] = url('node/' . $nid);
00189   $vars['title'] = check_plain($node->title);
00190 
00191   $info = array();
00192   $info['type'] = node_type_get_name($node);
00193   $info['user'] = theme('username', array('acccount' => $node));
00194   $info['date'] = format_date($node->changed, 'small');
00195   $extra = module_invoke_all('node_search_result', $node);
00196   if (isset($extra) && is_array($extra)) {
00197     $info = array_merge($info, $extra);
00198   }
00199   $vars['info_split'] = $info;
00200   $vars['info'] = implode(' - ', $info);
00201 
00202   $vars['node'] = $node;
00203   // @todo: get score from ???
00204 //$vars['score'] = $item->score;
00205   $vars['snippet'] = search_excerpt($vars['view']->value, $node->body);
00206 }
00207 
00208 

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1