未找到“ZendSearchLuceneLucene"类 ZendFramework2 [英] Class 'ZendSearchLuceneLucene' not found ZendFramework2

查看:41
本文介绍了未找到“ZendSearchLuceneLucene"类 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 安装了 Zendskeleton所以,我不知道我在这里缺少什么.

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

比,在同一个 ,它教如何使用 ZendSearch,但我没有得到相同的结果,而是我得到一个致命错误:致命错误:在/var/www 中找不到类'ZendSearchLuceneLucene'/CommunicationApp/module/Users/src/Users/Controller/SearchController.php 第 107 行

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 'ZendSearchLuceneLucene' not found in /var/www/CommunicationApp/module/Users/src/Users/Controller/SearchController.php on line 107

<?php
namespace UsersController;

use ZendMvcControllerAbstractActionController;
use ZendViewModelViewModel;

use ZendHttpHeaders;

use ZendAuthenticationAuthenticationService;
use ZendAuthenticationAdapterDbTable as DbTableAuthAdapter;

use UsersFormRegisterForm;
use UsersFormRegisterFilter;

use UsersModelUser;
use UsersModelUserTable;
use UsersModelUpload;

use UsersModelImageUpload;
use UsersModelImageUploadTable;

use ZendSearchLucene;
use ZendSearchLuceneDocument;
use ZendSearchLuceneIndex;

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 = LuceneLucene::open($searchIndexLocation);
            $searchResults = $index->find($queryText);
        }

        // prepare search form
        $form  = new endFormForm();
        $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 = LuceneLucene::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= DocumentField::unIndexed('upload_id', $fileUpload->id);
            // label field
            $label = DocumentField::Text('label', $fileUpload->label);
            // owner field          
            $owner = DocumentField::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 = LuceneDocumentXlsx::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 = LuceneDocumentDocx::loadDocxFile($uploadPath ."/" . $fileUpload->filename);
            } else {
                $indexDoc = new LuceneDocument();
            }
            $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. 删除您的 vendor 文件夹
  2. 编辑您的 composer.json 并将 zendframework/zendsearch 添加到要求部分
  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 URL 添加到您的 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"
    }
],

然后再试一次.

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

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