Skip to:
Content

bbPress.org

Changeset 2449


Ignore:
Timestamp:
06/28/2010 07:26:48 PM (11 years ago)
Author:
chrishajer
Message:

Better pagination for search results for #1274. Props GautamGupta

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/functions.bb-meta.php

    r2448 r2449  
    298298            break;
    299299        case 'version':
    300             return '1.1-alpha-2448'; // Don't filter
     300            return '1.1-alpha-2449'; // Don't filter
    301301            break;
    302302        case 'bb_db_version' :
  • trunk/search.php

    r2440 r2449  
    88
    99if ( $q = stripslashes( $q ) ) {
    10     /* Paging hack */
    11     global $page;
    12     if ( !$page ) $page = 1;
    1310    $per_page = ceil( (int) bb_get_option( 'page_topics' ) / 2 );
    14     $search_start = $per_page * ( $page - 1 );
    15     $search_stop = $per_page;
    1611   
    1712    /* Recent */
    1813    add_filter( 'bb_recent_search_fields',   create_function( '$f', 'return $f . ", MAX(post_time) AS post_time";' ) );
    1914    add_filter( 'bb_recent_search_group_by', create_function( '', 'return "t.topic_id";' ) );
    20     $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'page' => 1, 'per_page' => -1, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' );
     15    $bb_query_form->BB_Query_Form( 'post', array(), array( 'order_by' => 'p.post_time', 'count' => true, 'per_page' => $per_page, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_recent_search' );
    2116    $recent = $bb_query_form->results;
    22     if ( $recent ) {
    23         $recent_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $recent );
    24         $recent = array_slice( $recent, $search_start, $search_stop );
    25     } else {
    26         $recent_count = 0;
    27     }
     17    $recent_count = $recent ? $bb_query_form->found_rows : 0;
    2818   
    2919    /* Relevant */
    30     $bb_query_form->BB_Query_Form( 'topic', array( 'search' => $q ), array( 'page' => 1, 'post_status' => 0, 'per_page' => -1, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' );
     20    $bb_query_form->BB_Query_Form( 'topic', array( 'search' => $q ), array( 'per_page' => $per_page, 'count' => true, 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author' ), 'bb_relevant_search' );
    3121    $relevant = $bb_query_form->results;
    32     if ( $relevant ) {
    33         $relevant_count = isset( $bb_query_form->count ) ? $bb_query_form->count : count( $relevant );
    34         $relevant = array_slice( $relevant, $search_start, $search_stop );
    35     } else {
    36         $relevant_count = 0;
    37     }
     22    $relevant_count = $relevant ? $bb_query_form->found_rows : 0;
    3823   
    3924    $search_count = max( $recent_count, $relevant_count );
     
    5641endif;
    5742
    58 bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'page', 'per_page', 'search_count' ), $q );
    59 
    60 ?>
     43bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'per_page', 'search_count' ), $q );
Note: See TracChangeset for help on using the changeset viewer.