Skip to:
Content

bbPress.org

Ticket #1274: search.php.diff

File search.php.diff, 2.7 KB (added by GautamGupta, 16 years ago)

Better way to do pagination

  • search.php

     
    77$bb_query_form = new BB_Query_Form;
    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 );
    4025       
     
    5540                $topics = bb_append_meta( $topics, 'topic' );
    5641endif;
    5742
    58 bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'page', 'per_page', 'search_count' ), $q );
    59 
    60 ?>
    61  No newline at end of file
     43bb_load_template( 'search.php', array( 'q', 'recent', 'relevant', 'per_page', 'search_count' ), $q );