我正在使用Zend Lucene Search:
......
$results = $test->fetchAll();
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
foreach ($results as $result) {
$doc = new Zend_Search_Lucene_Document();
// add Fields
$doc->addField(
Zend_Search_Lucene_Field::Text('testid', $result->id));
$doc->addField(
Zend_Search_Lucene_Field::Keyword('testemail', strtolower(($result->email))));
$doc->addField(
Zend_Search_Lucene_Field::Text('testconfirmdate', $result->confirmdate));
$doc->addField(
Zend_Search_Lucene_Field::Text('testcreateddate', $result->createddate));
// Add document to the index
$index->addDocument($doc);
}
// Optimize index.
$index->optimize();
// Search by query
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
if(strlen($Data['name']) > 2){
//$query = Zend_Search_Lucene_Search_QueryParser::parse($Data['name'].'*');
$pattern = new Zend_Search_Lucene_Index_Term($Data['name'].'*');
$query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$this->view->hits = $index->find(strtolower($query));
}
else{
$query = $Data['name'];
$this->view->hits = $index->find($query);
}
............
在这里工作正常:
我的问题是:
Wildcard search is supported only for non-multiple word terms
”1234
”或09/06/2011
之类的数字/日期时,我收到错误消息“在模式开头至少需要3个非通配符”我想在这里搜索日期,电子邮件,电话号码。
答案 0 :(得分:0)
在文件zend / search / Lucene / search / search / query / wildcard中设置参数,
private static $_minPrefixLength = 3;
chnage它可能有用..!
答案 1 :(得分:0)
根据NaanuManu的建议,我做了一点挖掘来解决这个问题 - 我在一个相关的问题here上发布了我的答案,但是为方便起见重复:
直接从Zend Reference documentation获取,您可以使用:
Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength()
来
查询所需的最小前缀长度和Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength()
来
设置它。所以我的建议是两件事:
使用Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0)
使用javascript或其他方式验证所有搜索查询,以确保在使用任何通配符之前至少有Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength()
(我建议查询而不是假设默认值为“3”,以便验证灵活)