我正在尝试实施Zend_Search_Lucene
. 我已经在以下条件下实现了它:
- 搜索词*
- 搜索词
- 不区分大小写
但有时我收到错误为“ Wildcard search is supported only for non-multiple word terms
”
下面是我要搜索的一段代码,我从控制器中获取。
...
$browseSrArray = array();
if ($postData['name'])
$browseSrArray['name'] = preg_replace('#[^\w()/.%\-&]#', "", $postData['name']);
$results = $manufacturers->browseSearch($browseSrArray);
if(count($results)>0){
foreach ($results as $result) {
$doc = new Zend_Search_Lucene_Document();
// add Fields
$doc->addField(Zend_Search_Lucene_Field::Keyword('AccountNumber', $result['accountid']));
$doc->addField(Zend_Search_Lucene_Field::Keyword('ManufacturesName', strtolower($result['name'])));
$doc->addField(Zend_Search_Lucene_Field::Text('ContactName', $result['contact_name']));
$doc->addField(Zend_Search_Lucene_Field::Keyword('EmailId', strtolower($result['email'])));
$doc->addField( Zend_Search_Lucene_Field::Text('ManufacturesId', $result['manufacturer_id']));
$doc->addField(Zend_Search_Lucene_Field::Text('Manufacturesstatus', $result['status']));
// Add document to the index
$index->addDocument($doc);
}
// Optimize index.
$index->optimize();
if(strlen($postData['name']) > 2)
$query = Zend_Search_Lucene_Search_QueryParser::parse(strtolower($postData['name'].'*'));
else
$query = $postData['name'];
// Search by query
$this->view->hits = $index->find(strtolower($query));
} else {
$this->view->hits = 0;
}
...
需要修复以下情况。
例如,
- 如果我的制造商名称为“
testname-lastname
”,则会出现此错误。 - 如果我的制造商名称为“
firstname lastname
”,当我搜索 lastname 时,我不会从 lucence 得到准确的 LIKE 结果。
请帮我解决这个问题。