Question

I would like to integrate zend search into a native PHP project. I am getting all kinds of include errors.

I have done some research and it seems that there are a lot old articles about it written before zf2. With zf1 it used to be straight forward. Include lucene.php and that was it.

However since the release of zf2 the search component is no longer part of the zf2's skeleton and is down-loadable separately. When I included the Lucene.php, the script stars complaining about missing classes. (Include problem)

Should I include all the files or should I use some kind of a autoloader?

Was it helpful?

Solution 2

Start by making sure that you have installed the following:

  • curl (Make sure that you have added curl to the path environment variable)
  • composer

Make sure that openssl has been enabled in the php.ini used by the command line. (For those using wamp on windows, there are two php ini files. One for the apache and another one for the command line.)

Fire up the command line and use the CD command to go the directory where you have unzipped zend search and run the following two commands

curl -s h**ps://getcomposer.org/installer | php

php composer.phar install

create a php file in the same directory and include .vendor/autoload.php

Create an create an autoload function to load the different libraries. For the moment I have wrote something simple as the following:

function autoload($classname) {
$path = __DIR
. DS . "library" .DS . $classname . ".php";

if(file_exists($path)) { require_once($path);
} }

This should load the different classes providing that you know their namespace. This is basic autoloader and should not be used.

I have been using the following guide however it's outdated as the name of the classes have been modified to something like the following:

$indexPath = 'C:\wamp\www\storage'; $index = ZendSearch\Lucene\Lucene::create($indexPath);

$doc = new ZendSearch\Lucene\Document();

$doc->addField(ZendSearch\Lucene\Document\Field::UnIndexed('url', $docUrl)); $doc->addField(ZendSearch\Lucene\Document\Field::UnIndexed('created', $docCreated)); $doc->addField(ZendSearch\Lucene\Document\Field::UnIndexed('teaser', $docTeaser)); $doc->addField(ZendSearch\Lucene\Document\Field::Text('title', $docTitle)); $doc->addField(ZendSearch\Lucene\Document\Field::Text('author', $docAuthor)); $doc->addField(ZendSearch\Lucene\Document\Field::UnStored('contents', $docBody));

$index->addDocument($doc); $index->commit();

OTHER TIPS

You can use Composer to install individual ZF2 packages, and this will take care of any autoloading and dependencies for you.

https://github.com/zendframework/ZendSearch

You can see it also needs

zendframework/zend-stdlib

Download the repository and then install with composer, this will also get the dependencies for you, and setup autoloading.

php composer.phar install
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top