zend_search_lucene 中面临的问题
我正在使用 Zend Lucene 搜索:
......
$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);
}
............
这里工作正常:
- 当我给出完整的单词、前 3 个字符、不区分大小写的单词时,它可以工作
我的问题是:
- 当我搜索电子邮件时,我收到类似“
通配符搜索仅支持非多个单词术语
“ - 当我搜索“
1234
”或09/06/2011
等数字/日期时,我收到类似“至少 3模式开头需要非通配符”
我想在此处搜索日期、电子邮件、号码。
I am using 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);
}
............
Works fine here:
- It works when I give complete word, first 3 character, case insensitive words
My issues are:
- When I search for email, i got error like "
Wildcard search is supported only for non-multiple word terms
" - When I search for number/date like "
1234
" or09/06/2011
, I got error like "At least 3 non-wildcard characters are required at the beginning of pattern"
I want to search date, email, number here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在文件 zend/search/Lucene/search/search/query/wildcard 中设置了一个参数,
更改它,它可能会工作..!
In file zend/search/Lucene/search/search/query/wildcard a parameter is set,
chnage it and it may work..!
根据 NaanuManu 的建议,我做了更多的挖掘来解决这个问题 - 我在此处发布了我对相关问题的回答,但为了方便重复:
直接取自 Zend 参考文档,您可以使用:
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”,以便验证灵活)Based on NaanuManu's suggestion, I did a little more digging to figure this out - I posted my answer on a related question here, but repeating for convenience:
Taken directly from the Zend Reference documentation, you can use:
Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength()
toquery the minimum required prefix length and
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength()
toset it.
So my suggestion would be either of two things:
Set the prefixMinLength to 0 using
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0)
Validate all search queries using javascript or otherwise to ensure there is a minimum of
Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength()
before any wildcards used (I recommend querying that instead of assuming the default of "3" so the validation is flexible)