Sunday morning, I downloaded WAMP5 and the Zend Framework 1.0.3. I'd like to
search a mysql database. I can't figure out how to have Zend_Search_Lucene
connect and search through the database. I've seen tutorials to search
through RSS feeds. But I've been trying to change them to reflect a db
search. my database name is album, and it has two fields: artist, title.

Here is what I have so far. But I think my error is in the logic. I've tried
googling, but I can't seem to figure out how to search a mysql database
through Zend_Search_Lucene

If anyone can help me here, I would greatly appreciate it. thank you. I am a
bit lost..
<code>
function searchAction()
    {
        $this->view->title = "Search";
        require_once 'Zend/Search/Lucene.php';
        if ($this->_request->isPost()) {
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            $filter = new Zend_Filter_StripTags();
            
                echo "inside if";
        $artist = $filter->filter($this->_request->getPost('artist'));
        $artist = trim($artist);
        $title = trim($filter->filter($this->_request->getPost('title')));
        
        
        echo $artist,$title;
        $index = new Zend_Search_Lucene('/tmp/feeds_index',true);
        $doc = new Zend_Search_Lucene_Document();
                 $doc->addField(
                 Zend_Search_Lucene_Field::Text($artist) );
                 $doc->addField(
                 Zend_Search_Lucene_Field::Text($title) );
                 $index->addDocument($doc);
                                
                 // Commit these changes to the index.
                 $index->commit();
  
    
                if ($artist != '' && $title != '') {
                        $data = array(
                            'artist' => $artist,
                            'title'  => $title,
                        );
                        //$album = new Album();
                        //$album->insert($data);
                        //printf($data);
                        //open the index
                        $index = new Zend_Search_Lucene('/tmp/feeds_index');
                                //open the index
                                
                        $hits = $index->find($data);
                        
                        echo "Index contains ".$index->count()." 
documents.\n\n";

                                echo "Search for '".$query."' returned " 
.count($hits). " hits\n\n";
                                
                                foreach ($hits as $hit) {
                                        //echo $hit->title."\n";
                                        echo "\t Artist: ".sprintf('%.2f', 
$hit->artist)."\n";
                                        echo "\t Title: ".$hit->title."\n\n";
                                }

                
                    $this->_redirect('/');
                    return;
            }
        } 
    
         
        // set up an "empty" album
        //$album = new Album();
        //$this->view->album = $album->createRow();
    
        // additional view fields required by form
        echo "outside if";
        $this->view->action = 'search';
        $this->view->buttonText = 'Search';
        
        
        
    }
</code>        
    

This gives me numerous errors:

Fatal error: Uncaught exception 'Zend_Search_Lucene_Exception' with message
'Query must be a string or Zend_Search_Lucene_Search_Query object' in
C:\wamp\www\zf-tutorial\library\Zend\Search\Lucene.php:591 Stack trace: #0
C:\wamp\www\zf-tutorial\application\controllers\IndexControl ler.php(117):
Zend_Search_Lucene->find(Array) #1
C:\wamp\www\zf-tutorial\library\Zend\Controller\Action.php(4 99):
IndexController->searchAction() #2
C:\wamp\www\zf-tutorial\library\Zend\Controller\Dispatcher\S
tandard.php(242): Zend_Controller_Action->dispatch('searchAction') #3
C:\wamp\www\zf-tutorial\library\Zend\Controller\Front.php(92 9):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #4
C:\wamp\www\zf-tutorial\index.php(33): Zend_Controller_Front->dispatch() #5
{main} thrown in C:\wamp\www\zf-tutorial\library\Zend\Search\Lucene.php on
line 591

-- 
View this message in context: 
http://www.nabble.com/Zend_Search_Lucene-to-search-mysql-db-tf4937458s16154.html#a14132767
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to