Zend Search Lucene不区分大小写的搜索不起作用

时间:2015-05-08 11:50:15

标签: php lucene zend-search-lucene

我有一个Search类,有

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

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,问题是我将字段(名称等)保存为keyword,我将其更改为text,现在它正常运行。