作者:现实-不过如此 | 来源:互联网 | 2023-05-19 17:36
IvegotaSearchclass,wichhas我有一个搜索课,有publicfunction__construct($isNewIndexfalse){
I've got a Search class, wich has
我有一个搜索课,有
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";
}
}
I've got a record with name Test
, when I'm looking for Test
it works, but can't find this record with request test
Code example:
我有一个名为Test的记录,当我正在寻找Test它可以工作时,但找不到这条记录请求测试代码示例:
$s = new Search();
$s->find('test', 1232);//no results
1 个解决方案