Changeset 13197

Show
Ignore:
Timestamp:
10/31/07 10:17:03 (1 year ago)
Author:
rambo
Message:

forward port r13196 r13033 r13034 and r13082

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.search/viewer.php

    r12972 r13197  
    3131         
    3232        // Resultlists, controlled using HTTP GET/POST 
    33                $this->_request_switch[] = Array ( 'fixed_args' => 'result', 'no_cache' => true, 'handler' => 'result' ); 
     33        $this->_request_switch[] = Array ( 'fixed_args' => 'result', 'no_cache' => true, 'handler' => 'result' ); 
    3434         
    3535        // Advanced search form, no args 
    3636        $this->_request_switch['advanced'] = Array ( 'fixed_args' => 'advanced', 'handler' => 'searchform' ); 
    3737    } 
    38      
    39      
     38 
    4039    /** 
    4140     * Search form handler, nothing to do here. 
     
    7170        return true; 
    7271    } 
    73      
     72 
    7473    /** 
    7574     * Search form show handler, displays the search form, including 
     
    9392        if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
    9493        { 
    95             $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
    96         } 
     94            $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '")'; 
     95        } 
     96    } 
     97 
     98    /** 
     99     * Expand arrays of custom rules to end of query 
     100     * 
     101     * @param $final_query reference to the query string to be passed on to the indexer. 
     102     * @param $terms array or string to append 
     103     */ 
     104    function append_terms_recursive(&$final_query, $terms) 
     105    { 
     106        if (is_array($terms)) 
     107        { 
     108            foreach ($terms as $term) 
     109            { 
     110                $this->append_terms_recursive($final_query, $term); 
     111            } 
     112            return; 
     113        } 
     114        if (is_string($terms)) 
     115        { 
     116            $final_query .= "{$terms}"; 
     117            return; 
     118        } 
     119        debug_push_class(__CLASS__, __FUNCTION__); 
     120        debug_add('Don\'t know how to handle terms of type: ' . gettype($terms), MIDCOM_LOG_ERROR); 
     121        debug_print_r('$terms', $terms); 
     122        debug_pop(); 
     123        return; 
    97124    } 
    98125 
     
    157184        { 
    158185            case 'basic': 
    159                                $final_query = $data['query']; 
     186                $final_query = $data['query']; 
    160187                $this->add_multilang_terms($final_query); 
    161188                debug_add("Final query: {$final_query}"); 
    162                                $result = $indexer->query($final_query); 
     189                $result = $indexer->query($final_query); 
    163190                break; 
    164191             
    165192            case 'advanced': 
    166                                $data['request_topic'] = trim($_REQUEST['topic']); 
     193                $data['request_topic'] = trim($_REQUEST['topic']); 
    167194                $data['component'] = trim($_REQUEST['component']); 
    168195                $data['lastmodified'] = (integer) trim($_REQUEST['lastmodified']); 
     
    201228                    } 
    202229                    $final_query .= "__COMPONENT:{$data['component']}"; 
     230                } 
     231 
     232                // Way to add very custom terms 
     233                if (isset($_REQUEST['append_terms'])) 
     234                { 
     235                    $this->append_terms_recursive($final_query, $_REQUEST['append_terms']); 
    203236                } 
    204237 
     
    231264        if ($count > 0) 
    232265        { 
    233                $results_per_page = $this->_config->get('results_per_page'); 
    234                $max_pages = ceil($count / $results_per_page); 
     266            $results_per_page = $this->_config->get('results_per_page'); 
     267            $max_pages = ceil($count / $results_per_page); 
    235268            $page = min($_REQUEST['page'], $max_pages);  
    236                $first_document_id = ($page - 1) * $results_per_page; 
     269            $first_document_id = ($page - 1) * $results_per_page; 
    237270            $last_document_id = min(($count - 1), (($page * $results_per_page) - 1)); 
    238                 
    239                $data['page'] = $page; 
     271             
     272            $data['page'] = $page; 
    240273            $data['max_pages'] = $max_pages; 
    241274            $data['first_document_number'] = $first_document_id + 1; 
     
    248281        return true; 
    249282    } 
    250      
     283 
    251284    /** 
    252285     * Displays the resultset.