/[drupal]/contributions/modules/xapian/views-sample.txt
ViewVC logotype

Contents of /contributions/modules/xapian/views-sample.txt

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sun May 11 10:47:39 2008 UTC (18 months, 2 weeks ago) by simon
Branch: MAIN
CVS Tags: DRUPAL-5--1-1, DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/plain
Initial commit of xapian module
Created by LachlanGunn: Proof of concept and development for faster views integrated searches
Updated by Singularo: Converted to fully php based indexer, added core drupal patch and made ready for committing to CVS
1 //
2 // The code below can be used to show either a xapian based search view, or a normal view,
3 // depending on whether the xapian module is available and enabled.
4 //
5 // Speed of views using this is significantly faster than using the drupal core search,
6 // or views_fastsearch.
7 //
8
9
10 //
11 // Make pager globals available
12 //
13 global $pager_total;
14 global $pager_page_array;
15
16 // Load the view
17 $view = views_get_view($type);
18
19 if ($view) {
20 $view->url = $_GET['q'];
21
22 // If Xapian is available, perform the query from the xapian database
23 if (module_exists('xapian') && xapian_available()) {
24 if (!empty($_REQUEST['page'])) {
25 $page = $_REQUEST['page'];
26 }
27 else {
28 $page = 0;
29 }
30
31 // Setup paging
32 $start = $view->nodes_per_page * $page;
33 $length = (int)$view->nodes_per_page;
34
35 // Perform xapian query
36 list($count, $nids) = xapian_query($query, $start, $length, $other);
37
38 // Set pager globals to new values
39 $pager_total[0] = ($count / $view->nodes_per_page) + 1;
40 $pager_page_array[0] = $page;
41
42 // We should be able to do this more generically, and make a xapian_build_view() function, as the rest
43 // is already pretty generic
44 $results = array();
45 foreach ($nids as $nid) {
46 $node = node_load(array('nid' => $nid));
47 if ($node) {
48 $node_user = user_load(array('uid' => $node->uid));
49
50 $results[] = (object)array(
51 'nid' => $nid,
52 'node_title' => $node->title,
53 'node_changed' => $node->changed,
54 'users_uid' => $node_user->uid,
55 'users_name' => $node_user->name,
56 );
57 }
58 }
59
60 // Contruct header
61 $view->table_header = _views_construct_header($view, _views_get_fields());
62 }
63 else {
64 // Use standard views
65 $items = views_build_view('items', $view, array($folder), $view->use_pager, $view->nodes_per_page, 0, 0, $filters);
66 $results = $items['items'];
67 }
68
69 // If there are results, and a view, display the results and the pager
70 if (count($results)) {
71 if ($view) {
72 $output .= views_theme('views_view', $view, $view->type, $results, $view->info['level'], array($folder));
73
74 // Add standard pager
75 $output .= theme('pager', '', $view->pager_limit, 0);
76
77 }
78 }
79 }
80

  ViewVC Help
Powered by ViewVC 1.1.2