没有找到类ZendSearch \Lucene\Lucene'ZendFramework2 [英] Class 'ZendSearch\Lucene\Lucene' not found ZendFramework2

查看:185
本文介绍了没有找到类ZendSearch \Lucene\Lucene'ZendFramework2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用这些命令安装了ZendSearch和composer:

I've installed ZendSearch with composer using these commands:

$ cd /var/www/CommunicationApp/vendor/
$ git clone https://github.com/zendframework/ZendSearch.git
ZendSearch
$ cd ZendSearch/
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install

我已经根据 GITHUB
所以,我不知道我在这里错过了什么。

And I've installed Zendskeleton according to GITHUB So, I don't know What I'm missing here.

,它教会如何使用ZendSearch,但我没有得到相同的结果,而是我得到一个致命错误:致命错误:Class'ZendSearch \Lucene \Lucene'找不到/无功/网络/ CommunicationApp /模块/用户/ SRC /用户/控制器/硒第107行的archController.php

Than, in the same book, it teaches how to use ZendSearch, but I'm not getting the same results, instead I'm getting a Fatal error: Fatal error: Class 'ZendSearch\Lucene\Lucene' not found in /var/www/CommunicationApp/module/Users/src/Users/Controller/SearchController.php on line 107

<?php
namespace Users\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Http\Headers;

use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\DbTable as DbTableAuthAdapter;

use Users\Form\RegisterForm;
use Users\Form\RegisterFilter;

use Users\Model\User;
use Users\Model\UserTable;
use Users\Model\Upload;

use Users\Model\ImageUpload;
use Users\Model\ImageUploadTable;

use ZendSearch\Lucene;
use ZendSearch\Lucene\Document;
use ZendSearch\Lucene\Index;

class SearchController extends AbstractActionController
{
    protected $storage;
    protected $authservice;

    public function getAuthService()
    {
        if (! $this->authservice) {
            $this->authservice = $this->getServiceLocator()->get('AuthService');
        }
        return $this->authservice;
    }

    public function getIndexLocation()
    {
        // Fetch Configuration from Module Config
        $config  = $this->getServiceLocator()->get('config');
        if ($config instanceof Traversable) {
            $config = ArrayUtils::iteratorToArray($config);
        }
        if (!empty($config['module_config']['search_index'])) {
            return $config['module_config']['search_index'];
        } else {
            return FALSE;
        }
    }

    public function getFileUploadLocation()
    {
        // Fetch Configuration from Module Config
        $config  = $this->getServiceLocator()->get('config');
        if ($config instanceof Traversable) {
            $config = ArrayUtils::iteratorToArray($config);
        }
        if (!empty($config['module_config']['upload_location'])) {
            return $config['module_config']['upload_location'];
        } else {
            return FALSE;
        }
    }   

    public function indexAction()
    {
        $request = $this->getRequest();
        if ($request->isPost()) {
            $queryText = $request->getPost()->get('query');
            $searchIndexLocation = $this->getIndexLocation();
            $index = Lucene\Lucene::open($searchIndexLocation);
            $searchResults = $index->find($queryText);
        }

        // prepare search form
        $form  = new \Zend\Form\Form();
        $form->add(array(
            'name' => 'query',
            'attributes' => array(
                'type'  => 'text',
                'id' => 'queryText',
                'required' => 'required'
            ),
            'options' => array(
                'label' => 'Search String',
            ),
        ));
        $form->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Search', 
                'style' => "margin-bottom: 8px; height: 27px;"
            ),
        ));

        $viewModel  = new ViewModel(array('form' => $form, 'searchResults' => $searchResults));
        return $viewModel;
    }


    public function generateIndexAction()
    {
        $searchIndexLocation = $this->getIndexLocation();
        $index = Lucene\Lucene::create($searchIndexLocation);

        $userTable = $this->getServiceLocator()->get('UserTable');
        $uploadTable = $this->getServiceLocator()->get('UploadTable');
        $allUploads = $uploadTable->fetchAll();  
        foreach($allUploads as $fileUpload) {
            //
            $uploadOwner = $userTable->getUser($fileUpload->user_id);

            // id field
            $fileUploadId= Document\Field::unIndexed('upload_id', $fileUpload->id);
            // label field
            $label = Document\Field::Text('label', $fileUpload->label);
            // owner field          
            $owner = Document\Field::Text('owner', $uploadOwner->name);


            if (substr_compare($fileUpload->filename, ".xlsx", strlen($fileUpload->filename)-strlen(".xlsx"), strlen(".xlsx")) === 0) {
                // index excel sheet
                $uploadPath    = $this->getFileUploadLocation();
                $indexDoc = Lucene\Document\Xlsx::loadXlsxFile($uploadPath ."/" . $fileUpload->filename);
            } else if (substr_compare($fileUpload->filename, ".docx", strlen($fileUpload->filename)-strlen(".docx"), strlen(".docx")) === 0) {
                // index word doc
                $uploadPath    = $this->getFileUploadLocation();
                $indexDoc = Lucene\Document\Docx::loadDocxFile($uploadPath ."/" . $fileUpload->filename);
            } else {
                $indexDoc = new Lucene\Document();
            }
            $indexDoc->addField($label);
            $indexDoc->addField($owner);
            $indexDoc->addField($fileUploadId);
            $index->addDocument($indexDoc);
        }
        $index->commit();
    }

}


推荐答案

这本书给了你怪异的说明,因为它说Zend Search不能通过安装。作曲家,但这不再是事实不完全正确。修正:

The book is giving you weird instructions because it says Zend Search cannot be installed via. Composer, but this is no longer the case not quite true. To fix:


  1. 删除您的供应商文件夹

  2. 编辑您的 composer.json 并将 zendframework / zendsearch 添加到require部分
  3. 运行 php composer.phar install 来安装所有软件包(包括Zend Search)
  1. Delete your vendor folder
  2. Edit your composer.json and add zendframework/zendsearch to the require section
  3. Run php composer.phar install to install all packages (including Zend Search)

然后,一切都应该工作。

Then everything should be working.

编辑:好的,由于某些原因,此软件包未列入packagist。您还需要将repo网址添加到您的composer.json中:

Edit: okay, for some reason this package isn't listed on packagist. You'll also need to add the repo URL to your composer.json:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/zendframework/ZendSearch"
    }
],

然后再试一次。

这篇关于没有找到类ZendSearch \Lucene\Lucene'ZendFramework2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆