-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfaceted_search_ui.inc
executable file
·99 lines (85 loc) · 2.61 KB
/
faceted_search_ui.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @file
* Provides classes needed by the Faceted Search UI module, and that are
* sometimes extended by other modules.
*/
/**
* Base class for display styles.
*/
class faceted_search_ui_style {
/**
* Return the number of nodes per page.
*/
function get_limit() {
return variable_get('default_nodes_main', 10);
}
}
/**
* Provides the 'extracts' display style for search results.
*/
class faceted_search_ui_extract_style extends faceted_search_ui_style {
/**
* Return the name of this style.
*/
function get_label() {
return t('Extracts');
}
/**
* Format the search results to display node extracts showing relevant
* keywords.
*/
function format_results($search) {
drupal_add_css(drupal_get_path('module', 'search') .'/search.css');
$found_items = $search->load_results($this->get_limit());
// Taken from node_search() (node.module 1.764) - BEGIN
$results = array();
foreach ($found_items as $item) {
// Build the node body.
$node = node_load($item->nid);
$node->build_mode = NODE_BUILD_SEARCH_RESULT;
$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);
// Fetch comments for snippet
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
// Fetch terms for snippet
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
$extra = node_invoke_nodeapi($node, 'search result');
$results[] = array(
'link' => url('node/'. $item->nid, array('absolute' => TRUE)),
'type' => check_plain(node_get_types('name', $node)),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
'node' => $node,
'extra' => $extra,
'score' => $item->score,
'snippet' => search_excerpt(implode(' ', $search->get_keywords()), $node->body),
);
}
// Taken from node_search() - END
return theme('faceted_search_ui_search_page', $results, 'node');
}
}
/**
* Provides the 'teasers' display style for search results.
*/
class faceted_search_ui_teaser_style extends faceted_search_ui_style {
/**
* Return the name of this style.
*/
function get_label() {
return t('Teasers');
}
/**
* Format the search results to display node teasers.
*/
function format_results($search) {
$limit = $this->get_limit();
$found_items = $search->load_results($limit);
foreach ($found_items as $item) {
$output .= node_view(node_load($item->nid), TRUE);
}
return $output . theme('pager', NULL, $limit);
}
}