search.views.inc

  1. cis7 sites/all/modules/ulmus/views/modules/search.views.inc
  2. cle7 sites/all/modules/ulmus/views/modules/search.views.inc
  3. ecd7 sites/all/modules/ulmus/views/modules/search.views.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/modules/search.views.inc
  5. harmony7 sites/all/modules/ulmus/views/modules/search.views.inc
  6. icor7 sites/all/modules/ulmus/views/modules/search.views.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/modules/search.views.inc
  8. mooc7 sites/all/modules/ulmus/views/modules/search.views.inc

Provide views data and handlers for search.module.

Functions

Namesort descending Description
search_views_data Implements hook_views_data().
search_views_plugins Implements hook_views_plugins().
template_preprocess_views_view_row_search Template helper for theme_views_view_row_search

File

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

Related topics