2015-05-08 115 views
0

我有一個搜索類,至極有的Zend的Lucene搜索不區分大小寫搜索無法正常工作

public function __construct($isNewIndex = false) { 
    setlocale(LC_CTYPE, 'ru_RU.UTF-8'); 

    $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive(); 
    $morphy = new Isi_Search_Lucene_Analysis_TokenFilter_Morphy('ru_RU'); 
    $analyzer->addFilter($morphy); 

    Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer); 
    Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); 

    //if it's true, then it creates new folder to the path in $_indexFieles; 
    if ($isNewIndex) { 
     $this->_indexes[$this->_key] = Zend_Search_Lucene::create(Yii::getPathOfAlias('application.' . $this->_indexFiles), true); 
    } else { 
     $this->_indexes[$this->_key] = Zend_Search_Lucene::open(Yii::getPathOfAlias('application.' . $this->_indexFiles)); 
    } 
} 

public function find($query, $eventId) 
{ 
    try 
    { 
     Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND); 
     $query = "($query) AND (event_id:$eventId)"; 
     Zend_Search_Lucene::setResultSetLimit(self::ACCREDITATION_LIMIT); 
     return $this->_indexes[$this->_key]->find("{$query}"); 
    } 
    catch (Zend_Search_Lucene_Search_QueryParserException $e) 
    { 
     echo "Query syntax error: " . $e->getMessage() . "\n"; 
    } 
    catch (Exception $e) 
    { 
     echo $e->getMessage(). "\n"; 
    } 
} 

我有一個紀錄名稱Test,當我在尋找Test它的工作原理,但無法找到該記錄與請​​求test 代碼示例:

$s = new Search(); 
$s->find('test', 1232);//no results 

回答

0

我找到了一個解決辦法,問題是我是拯救字段(名稱等)keyword,我把它改成text,並現在它正在工作完美。

+0

我面臨同樣的問題,你可以請包括你創建索引的代碼? – iamawebgeek