Changeset 12925

Show
Ignore:
Timestamp:
10/21/07 18:26:35 (1 year ago)
Author:
rambo
Message:

indexing/search multilang, first tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/midcom.core/midcom/services/indexer/backend/solr.php

    r11087 r12925  
    108108    function query ($query, $filter) 
    109109    { 
     110        debug_push_class(__CLASS__, __FUNCTION__); 
    110111        if ($filter !== null)  
    111112        { 
     
    119120            } 
    120121        } 
     122        /* In fact this is probably best left for midcom.helper.search to decide 
     123        if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
     124        { 
     125            $query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
     126        } 
     127        */ 
    121128 
    122129        $url = "http://" . $GLOBALS['midcom_config']['indexer_xmltcp_host'] .  
     
    136143            $msg = (is_object($err)) ? $err->getMessage() : ""; 
    137144            debug_add("Failed to execute Request {$url}:{$this->code} {$msg}", MIDCOM_LOG_WARN);  
     145            debug_pop(); 
    138146            return false; 
    139147        } 
    140      
    141         $response = DomDocument::loadXML($request->getResponseBody()); 
     148        $body = $request->getResponseBody(); 
     149        debug_add("Got response\n===\n{$body}\n===\n"); 
     150        $response = DomDocument::loadXML($body); 
    142151        $xquery = new DomXPath($response); 
    143152        $result = array(); 
     
    148157        } 
    149158 
    150         foreach ($xquery->query('/response/result/doc') as $res) { 
    151              
     159        foreach ($xquery->query('/response/result/doc') as $res) 
     160        { 
    152161            $doc = new midcom_services_indexer_document(); 
    153162            foreach ($res->childNodes as $str) { 
     
    163172                 
    164173            } 
    165             $result[$doc->RI] = $doc; 
    166         } 
     174            $result[] = $doc; 
     175        } 
     176        debug_add(sprintf('Returning %d results', count($result)), MIDCOM_LOG_INFO); 
     177        debug_pop(); 
    167178        return $result; 
    168179    } 
     
    283294     * posts the xml to the suggested url using HTTP_Request. 
    284295     * */ 
    285     function do_post($xml) { 
    286  
     296    function do_post($xml) 
     297    { 
     298        debug_push_class(__CLASS__, __FUNCTION__); 
    287299        $options = array(); 
    288300        $options['method'] = HTTP_REQUEST_METHOD_POST ; 
     
    295307        $this->request->addHeader('Accept-Charset', 'UTF-8'); 
    296308        $this->request->addHeader('Content-type', 'text/xml; charset=utf-8'); 
     309        debug_add("POSTing XML to {$url}\n===\n{$xml}\n===\n"); 
    297310        $err = $this->request->sendRequest(true); 
    298311 
     
    301314        if ($this->code != 200 || PEAR :: isError($err)) { 
    302315            debug_add("Failed to execute Request {$url}:{$this->code} {$err}", MIDCOM_LOG_WARN);  
    303             debug_add("Request content: \n$xml", MIDCOM_LOG_DEBUG);  
     316            debug_add("Request content: \n$xml", MIDCOM_LOG_DEBUG); 
     317            debug_pop(); 
    304318            return false; 
    305319        } 
     
    312326            debug_add("Failed to execute Request {$url}: {$err->getMessage()}", MIDCOM_LOG_WARN);  
    313327            debug_add("Request content: \n$xml", MIDCOM_LOG_INFO);  
     328            debug_pop(); 
    314329            return false; 
    315330        } 
     331        debug_add('POST ok'); 
     332        debug_pop(); 
    316333        return true; 
    317334 
  • branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document.php

    r11079 r12925  
    8888 
    8989    /** 
     90     * Two letter language code of the document contnet 
     91     * 
     92     * This field is optional. 
     93     * 
     94     * @var string 
     95     */ 
     96    var $lang = ''; 
     97 
     98    /** 
    9099     * The GUID of the topic the document is assigned to. May be empty for 
    91100     * non-midgard resources. 
     
    444453 
    445454        // __RI does not need to be populated, this is done by backends. 
     455        $this->add_unindexed('__LANG', $this->lang); 
    446456        $this->add_text('__TOPIC_GUID', $this->topic_guid); 
    447457        $this->add_text('__COMPONENT', $this->component); 
     
    493503    { 
    494504        $this->RI = $this->get_field('__RI'); 
     505        $this->lang = $this->get_field('__LANG'); 
    495506        $this->topic_guid = $this->get_field('__TOPIC_GUID'); 
    496507        $this->component = $this->get_field('__COMPONENT'); 
     
    517528        $this->type = $this->get_field('__TYPE'); 
    518529        $this->security = $this->get_field('__SECURITY'); 
     530 
     531        // Strip language code from end of RI if it looks like "<GUID>_<LANG>" (because *many* places suppose it's plain GUID) 
     532        $this->RI = preg_replace('/^([0-9a-f]{32,80})_[a-z]{2}$/', '\\1', $this->RI); 
    519533    } 
    520534 
     
    568582        debug_add("Editor: " . (! is_object($this->editor) ? 'none' : $this->editor->name), $loglevel); 
    569583        debug_add("RI: {$this->RI}", $loglevel); 
     584        debug_add("Language: {$this->lang}", $loglevel); 
    570585        debug_add("Score: {$this->score}", $loglevel); 
    571586        debug_add("Source: {$this->source}", $loglevel); 
  • branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document/midcom.php

    r5072 r12925  
    7171         
    7272        $this->source = $this->_metadata->object->guid(); 
    73         $this->RI = $this->source; 
     73        $this->lang = $_MIDCOM->i18n->get_content_language(); 
     74        $this->RI = "{$this->source}_{$this->lang}"; 
    7475        $this->document_url = $_MIDCOM->permalinks->create_permalink($this->source); 
    7576         
     
    7778        $this->_process_topic(); 
    7879    } 
    79      
     80 
     81    /* To simplify life wt indexer results we do this at master class level 
     82    function fields_to_members() 
     83    { 
     84        parent::fields_to_members(); 
     85        // Strip language code from end of RI if it looks like "<GUID>_<LANG>" (because *many* places suppose it's plain GUID) 
     86        $this->RI = preg_replace('/^([0-9a-f]{32,80})_[a-z]{2}$/', '\\1', $this->RI); 
     87    } 
     88    */ 
    8089     
    8190    /** 
  • branches/MidCOM_2_8/midcom.helper.search/viewer.php

    r6141 r12925  
    9797         
    9898        $data['type'] = $_REQUEST['type']; 
     99        $data['query'] = trim($_REQUEST['query']); 
     100        if (   $GLOBALS['midcom_config']['indexer_backend'] != 'solr' 
     101            && count(explode(' ', $data['query'])) == 1 
     102            && strpos($data['query'], '*') === false) 
     103        { 
     104            $data['query'] .= '*'; 
     105        } 
     106 
    99107         
    100108        switch ($data['type']) 
    101109        { 
    102110            case 'basic': 
    103                 $data['query'] = trim($_REQUEST['query']); 
    104                  
    105                                 if (   count(explode(' ', $data['query'])) == 1 
    106                                     && !strstr($data['query'], '*')) 
    107                                 { 
    108                                     // Single search term, append * 
    109                     if ($GLOBALS['midcom_config']['indexer_backend'] != 'solr')  
    110                     { 
    111                                         $data['query'] .= '*'; 
    112                     } 
    113                                 } 
    114111                                 
    115                                 $result = $indexer->query($data['query']); 
     112                                $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                } 
     117                                $result = $indexer->query($final_query); 
    116118                break; 
    117119             
    118120            case 'advanced': 
    119                 $data['query'] = trim($_REQUEST['query']); 
    120                  
    121                                 if (   count(explode(' ', $data['query'])) == 1 
    122                                     && !strstr($data['query'], '*') && $GLOBALS['midcom_config']['indexer_backend'] != 'solr' ) 
    123                                 { 
    124                                     // Single search term, append * 
    125                                     $data['query'] .= '*'; 
    126                                 } 
    127                                  
     121 
    128122                                $data['request_topic'] = trim($_REQUEST['topic']); 
    129123                $data['component'] = trim($_REQUEST['component']); 
     
    163157                    } 
    164158                    $final_query .= "__COMPONENT:{$data['component']}"; 
     159                } 
     160 
     161                if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 
     162                { 
     163                    $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 
    165164                } 
    166165                debug_add("Final query: {$final_query}");