[eluser]zimco[/eluser]
I followed the tutorial i found here:
http://www.cmjackson.net/2009/02/17/how-...deigniter/
I successfully got that working with CI2.X but now i want to use zend_search_lucene to search one of my MySQL databases and since the tutorial only shows how to search feeds, how do you search a database?
What changes need to be made to my controller pasted below to try indexing and searching a table in a MySQL database?
Home.php controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
/**
* Index Page for this controller.
*
* @see http://ellislab.com/codeigniter/user-guide/general/urls.html
*/
public function index() {
$this->load->library('zend', 'Zend/Feed');
$this->load->library('zend', 'Zend/Search/Lucene');
$this->load->library('zend');
$this->zend->load('Zend/Feed');
$this->zend->load('Zend/Search/Lucene');
//Create index.
$index = new Zend_Search_Lucene('/Library/WebServer/Documents/wostr/application/uploads/feeds_index', true);
$feeds = array(
'http://www.cmjackson.net/feed/rss/',
'http://andrewmjackson.com/feed/rss');
//grab each feed.
foreach($feeds as $feed)
{
$channel = Zend_Feed::import($feed);
echo $channel->title().'<br />';
//index each item.
foreach($channel->items as $item)
{
if ($item->link() && $item->title() && $item->description())
{
//create an index doc.
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Keyword(
'link', $this->sanitize($item->link())),'UTF-8');
$doc->addField(Zend_Search_Lucene_Field::Text(
'title', $this->sanitize($item->title())),'UTF-8');
$doc->addField(Zend_Search_Lucene_Field::Unstored(
'contents', $this->sanitize($item->description())),'UTF-8');
echo "\tAdding: ". $item->title() .'<br />';
$index->addDocument($doc);
}
}
}
$index->commit();
echo $index->count() .' Documents indexed.<br />';
}
public function sanitize($input)
{
return htmlentities(strip_tags($input),ENT_QUOTES,'UTF-8');
}
public function search() {
$this->load->library('zend', 'Zend/Search/Lucene');
$this->load->library('zend');
$this->zend->load('Zend/Search/Lucene');
$index = new Zend_Search_Lucene('/Library/WebServer/Documents/wostr/application/uploads/feeds_index');
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
$query = 'farm';
$hits = $index->find($query);
echo 'Index contains '. $index->count() .
' documents.<br /><br />';
echo 'Search for "'. $query .'" returned '. count($hits) .
' hits<br /><br />';
foreach($hits as $hit) {
echo $hit->title .'<br />';
echo 'Score: '. sprintf('%.2f', $hit->score) .'<br />';
echo $hit->link .'<br /><br />';
}
}
} /* End of file home.php */
/* Location: ./application/controllers/home.php */
I hope somebody that has used lucene search with codeigniter before can give me some advice on how to proceed!