Changeset 12934

Show
Ignore:
Timestamp:
10/22/07 07:57:44 (1 year ago)
Author:
rambo
Message:

copied sanity checks from trunk, moved ML terms to one method, remember to debug_pop

Files:

Legend:

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

    r12925 r12934  
    8383        midcom_show_style('search_form'); 
    8484    } 
    85      
     85 
     86    /** 
     87     * Appends language to search terms 
     88     * 
     89     * @param $final_query reference to the query string to be passed on to the indexer. 
     90     */ 
     91    function add_multilang_terms(&$final_query) 
     92    { 
     93        if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
     94        { 
     95            $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
     96        } 
     97    } 
     98 
    8699    /** 
    87100     * Queries the information from the index and prepares to display the result page. 
     
    94107    function _handler_result($handler_id, $args, &$data) 
    95108    { 
    96         $indexer =& $GLOBALS['midcom']->get_service('indexer'); 
    97          
     109        debug_push_class(__CLASS__, __FUNCTION__); 
     110        $indexer =& $_MIDCOM->get_service('indexer'); 
     111         
     112        // Sane defaults for REQUEST vars 
     113        if (!isset($_REQUEST['type'])) 
     114        { 
     115            $_REQUEST['type'] = 'basic'; 
     116        } 
     117        if (!isset($_REQUEST['page'])) 
     118        { 
     119            $_REQUEST['page'] = 1; 
     120        } 
     121        if (!isset($_REQUEST['component'])) 
     122        { 
     123            $_REQUEST['component'] = ''; 
     124        } 
     125        if (!isset($_REQUEST['topic'])) 
     126        { 
     127            $_REQUEST['topic'] = ''; 
     128        } 
     129        if (!isset($_REQUEST['lastmodified'])) 
     130        { 
     131            $_REQUEST['lastmodified'] = 0; 
     132        } 
     133        // If we don't have a query string, relocate to empty search form 
     134        if (!isset($_REQUEST['query'])) 
     135        { 
     136            debug_add('$_REQUEST["query"] is not set, relocating back to form', MIDCOM_LOG_INFO); 
     137            debug_pop(); 
     138            if ($data['type'] == 'basic') 
     139            { 
     140                $_MIDCOM->relocate(''); 
     141            } 
     142            $_MIDCOM->relocate('advanced/'); 
     143        } 
     144 
    98145        $data['type'] = $_REQUEST['type']; 
    99146        $data['query'] = trim($_REQUEST['query']); 
     147 
    100148        if (   $GLOBALS['midcom_config']['indexer_backend'] != 'solr' 
    101149            && count(explode(' ', $data['query'])) == 1 
    102150            && strpos($data['query'], '*') === false) 
    103151        { 
     152            /** 
     153             * If there is only one search term AND the backend is not Solr 
     154             * Append * to the query (Solr does this wilcard automagically) 
     155             */ 
    104156            $data['query'] .= '*'; 
    105157        } 
    106158 
    107          
    108159        switch ($data['type']) 
    109160        { 
    110161            case 'basic': 
    111                                  
    112162                                $final_query = $data['query']; 
    113                 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
    114                 { 
    115                     $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
    116                 } 
     163                $this->add_multilang_terms($final_query); 
     164                debug_add("Final query: {$final_query}"); 
    117165                                $result = $indexer->query($final_query); 
    118166                break; 
    119167             
    120168            case 'advanced': 
    121  
    122169                                $data['request_topic'] = trim($_REQUEST['topic']); 
    123170                $data['component'] = trim($_REQUEST['component']); 
     
    159206                } 
    160207 
    161                 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
    162                 { 
    163                     $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
    164                 } 
     208                $this->add_multilang_terms($final_query); 
    165209                debug_add("Final query: {$final_query}"); 
    166210                 
     
    171215                $this->errstr = "Wrong handler ID {$handler_id} for searchform handler"; 
    172216                $this->errcode = MIDCOM_ERRCRIT; 
     217                debug_pop(); 
    173218                return false; 
    174219        } 
     
    180225            // the indexer backend though (what would I give for a decent exectpion 
    181226            // handling here...) 
     227            debug_add('Got boolean false as resultset (likely broken query), casting to empty array', MIDCOM_LOG_WARN); 
    182228            $result = Array(); 
    183229        } 
     
    202248            $data['result'] = array_slice($result, $first_document_id, $results_per_page); 
    203249        } 
     250        debug_pop(); 
    204251        return true; 
    205252    }