Zend_Search_Lucence - Wildcard search is supported only for non-multiple word terms?

708 views Asked by At

I am trying to implement Zend_Search_Lucene. I have implemented it with following condition:

  1. searchword*
  2. searchword
  3. case insensitive

But some times I am getting error as "Wildcard search is supported only for non-multiple word terms"

Below is my piece of code to search, which I taken from controller.

...
$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;
}
...

Need to fix the following condition.

For example,

  1. If I have manufacture name as "testname-lastname" I got this error.
  2. If I have manufacture name as "firstname lastname", I will not get exact LIKE result from lucence when I search for lastname.

Kindly help me to fix this.

0

There are 0 answers