Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Zend Lucene search breaks on upgrading to CI 1.7 - Loader.php problem
#1

[eluser]MMacdonald[/eluser]
[ORIGINAL POST AND PROBLEM]

A couple of weeks ago I followed Andrew Rowland's guide to setting up Zend Lucene search with CodeIgniter. Since upgrading to CI 1.7, when I submit a search query, I get

Quote:Fatal error: Class 'Zend_Search_Lucene' not found in C:\xampp\htdocs\ccp\system\application\controllers\search.php

I'm really struggling to work out what's changed - I've retained all the Zend files. Does anyone with more knowledge of the internal changes in CI 1.7 have any ideas?

Zend Loader Class

Code:
class CI_Zend
{

    function __construct($class = NULL)
    {
        ini_set('include_path',
        ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

        if ($class)
        {
            require_once (string) $class . EXT;
            log_message('debug', "Zend Class $class Loaded");
        }
        else
        {
            log_message('debug', "Zend Class Initialized");
        }
    }

    function load($class)
    {
        require_once (string) $class . EXT;
        log_message('debug', "Zend Class $class Loaded");
    }
}

Search Controller

Code:
<?php
class Search extends Controller {

  function Search()
  {
  parent::Controller();
   $this->load->library('zend', 'Zend/Search/Lucene');
   $this->indexPath = APPPATH.'search/index';
  }


  function create()
  {
  $this->load->database();
  $this->db->select('id,title,summary,body');
  $query = $this->db->get('news');
  $result = $query->result();

  $index = Zend_Search_Lucene::create($this->indexPath);
  $doc = new Zend_Search_Lucene_Document();

  foreach($result as $item)
  {
  $doc->addField(Zend_Search_Lucene_Field::Text('title', $item->title));
  $doc->addField(Zend_Search_Lucene_Field::Text('summary', $item->summary));
  $doc->addField(Zend_Search_Lucene_Field::Text('body', $item->body));
  $doc->addField(Zend_Search_Lucene_Field::Text('path', 'news/view/'.$item->id));
  $index->addDocument($doc);
  }
  $index->commit();

  echo "index created";

}

function result()
  {
  $data=load_partials($this);
  $data['results'] = array();

   if ($this->input->post('search_query'))
    {
     $index = Zend_Search_Lucene::open($this->indexPath);
     $data['results'] = $index->find($this->input->post('search_query'));
    }

   $this->load->view('search/search_result', $data);
}

}
?>

Many thanks,
Mark

[UPDATE]
I've swapped the system/libraries/Loader.php from the 1.7 version back to the 1.6.3 version (keeping everything else on 1.7) - my code works again, so I know this is specifically to do with a change to the CI loader class. So my question is: is my code above now incorrect, or is this a bug in CI 1.7? I'm going to hunt through the 2 versions of Loader.php with a diff tool and try to figure out specifically what's causing this, but if anyone from EllisLabs who has worked on the Loader class has any ideas it could save me hours.

[CAUSE IDENTIFIED]
The CI 1.7 Change Log states:

Quote:Added the ability to assign library objects to your own variable names when you use $this->load->library(). Please see the Loader class for more info.

Line 72 of the new loader class (@param string - an optional object name) shows that it has been updated to allow for an extra parameter. This causes a conflict when Zend Lucene is loaded because the controller shown above passes 2 parameters:

Code:
$this->load->library('zend', 'Zend/Search/Lucene');

[FIX FOUND]

Replace

Code:
$this->load->library('zend', 'Zend/Search/Lucene');

with

Code:
$this->load->library('zend');
  $this->zend->load( 'Zend/Search/Lucene');

I hope this helps anyone else who is using Lucene.
#2

[eluser]junaids[/eluser]
hi.
I have used ur code and took some guide from andrew rowlands blog. but still i cant configure out how to use zend lucene in my application. if u can tell me what is load_partials function. bcz i am having an error on it. if i comment it i get the following error
Code:
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\codeigniter\system\application\controllers\search.php:53)

Filename: libraries/Session.php
#3

[eluser]TheFuzzy0ne[/eluser]
Check for any output before and after the <?php ?> tags.
#4

[eluser]junaids[/eluser]
if anybody else can show me how to use zend lucene with CI. i will be very thankful
#5

[eluser]TheFuzzy0ne[/eluser]
http://www.cmjackson.net/tutorials/how-t...deigniter/




Theme © iAndrew 2016 - Forum software by © MyBB