Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-17-2008, 11:03 PM
Junior Member
 
Join Date: Mar 2008
Posts: 15
Default Zend_Search_Lucene question

I was testing on the Zend_Search_Lucene, and I can't get this work properly, here is some of my testing code

I call this function in my indexAction

PHP Code:
    protected function buildDocument() {
        
$feed 'http://feeds.feedburner.com/ZendDeveloperZone';                
        
$this->_channel Zend_Feed::import($feed);        
        
        foreach(
$this->_channel->items as $item) {
            
            echo 
$item->link();
            
            
$doc = new Zend_Search_Lucene_Document();
            
            
$doc->addField(
                
Zend_Search_Lucene_Field::Keyword('link'$this->_injectFilter->filter($item->link()))
            );
                
            
$doc->addField(
                
Zend_Search_Lucene_Field::Text('title'$this->_injectFilter->filter($item->title()))
            );    
            
            
$doc->addField(
                
Zend_Search_Lucene_Field::UnStored('contents'$this->_injectFilter->filter($item->description()))
            );
            
            
$this->_index->addDocument($doc);
        }    

        
$this->_index->commit();
    } 
And then I try to fetch the result from my searchAction()

PHP Code:
    public function searchAction() {
         
$index Zend_Search_Lucene::create('/path/to/index');
         
$this->_helper->viewRenderer->setNoRender(true);
         
         echo 
"Index contains {$index->count()} documents.\n";
         
         
$query 'framework'// I try several other keywords as well, but still not working
        
          
$hits $index->find($query);
        
         echo 
"Search for '".$query."' returned " .count($hits). " hits<br /><br />";
        
         foreach(
$hits as $hit) {
             echo 
$hit->title '<br />';
             echo 
$hit->link '<br /><br />';
         }         
    } 
But I got
Index contains 0 documents.
Search for 'framework' returned 0 hits


When I check my indexing folder, I saw some files being created
segements.gen
_2.cfs and some other segements


Can someone tell me what have I done wrong or any suggestion, thanks for any help!

[ Note: the $this->_index is from Zend_Search_Lucene::create('/path/to/index'); ]

Last edited by iroy2000 : 03-17-2008 at 11:07 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-18-2008, 05:56 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Quote:
$index = Zend_Search_Lucene::create('/path/to/index');
You need to create/open your index before you can start indexing documents. Your index path should also be a real system path on your system that the web server can write to.

I created a static method that I can call to create/open my index:

Replace $GLOBALS['index_path'] with your real system path (I'm loading mine up from my config file).

PHP Code:
    public static function getIndex()
    {
        if (!
file_exists($GLOBALS['index_path'])) {
            
$index Zend_Search_Lucene::create($GLOBALS['index_path']);
        } else {
            
$index Zend_Search_Lucene::open($GLOBALS['index_path']);
        }
        
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num());
        return 
$index;
    } 
Then when ever you need to add a document or perform a query, you can call this method first and set it to your $index var, for all index operations (find, addDocument, etc)

Also, this tool can be handy to test your index out, though I think there are some differences between the two (result sets may vary, but is a decent enough way to test some things - just test them in your Zend_Search_Lucene as well): http://www.getopt.org/luke/
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-19-2008, 12:20 AM
Junior Member
 
Join Date: Mar 2008
Posts: 15
Default

Thanks for the reply, very helpful.

I tried to make a getSearchIndex() and it works. But now there's another problem...

The first time I run, it calls the "create()", and after that it calls "open()". It all make sense here.

So I tried to reload several times for testing, but each time of reload, it adds more "same" queries into the indexing.

Do I need to delete them before updating, or there is a better way to solve that problem??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-19-2008, 01:52 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

It's probably a good idea to delete what got started, and then run the getSearchIndex() method to create it the first time.

Then start to index your documents, and get your index filled with data. Use the Luke tool to ensure the index is readable and you can run a couple of queries against it for known data to ensure it's working.

Once you have your index populated, move on to creating your front end search methods and use them to use Zend_Search_Lucene to query your index. Once you're getting some hits back, dress up your results page, and you should be good to go.
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:07 AM.