Zend_Search_Lucence - 仅支持非多字词的通配符搜索?

时间:2011-11-08 07:19:52

标签: php zend-framework zend-lucene

我正在尝试实施Zend_Search_Lucene。我已经用以下条件实现了它:

  1. 搜索内容*
  2. 搜索内容
  3. 不区分大小写
  4. 但有时我收到错误为“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;
    }
    ...
    

    需要修正以下条件。

    例如,

    1. 如果我的制造商名称为“testname-lastname”,则会收到此错误。
    2. 如果我的制造商名称为“firstname lastname”,那么当我搜索姓氏时,我将无法从lucence获得精确的LIKE结果。
    3. 请帮我解决这个问题。

0 个答案:

没有答案