2013-12-20 26 views
0

我使用這些命令作曲家安裝ZendSearch:類「ZendSearch Lucene的 Lucene的」未找到ZendFramework2

$ 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,我不知道是什麼我在這裏失蹤。

比在同一book,它教導如何使用ZendSearch,但我沒有得到相同的結果,而是我得到一個致命錯誤:致命錯誤:沒有找到類'ZendSearch \ Lucene \ Lucene'在/var/www/CommunicationApp/module/Users/src/Users/Controller/SearchController.php線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(); 
    } 

} 
+0

請不要發佈關於同一個問題的多個問題。 –

回答

2

這本書是給你的怪異指令,因爲它說的Zend搜索不能通過安裝。作曲家,但這是不再是這種情況不完全正確。要解決:

  1. 刪除您vendor文件夾
  2. 編輯您的composer.json並添加zendframework/zendsearch到需要部分
  3. 運行php composer.phar install安裝所有的軟件包(包括Zend的搜索)

然後一切都應該是加工。

編輯:好的,出於某種原因,此軟件包未列入packagist。您還需要將回購網址添加到您的composer.json中:

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

然後再試一次。

+0

在任何版本中都找不到所需的zendframework/zendsearch軟件包,軟件包名稱中可能有拼寫錯誤。 – John

+0

我編輯了我的答案 –

+0

這確實奏效,謝謝! – John

0

你應該把zendsearch在供應商文件夾zendframework並安裝它作爲本書後說,你應該在vendor/composer/autoload_namespaces.php末插入此行:

'ZendSearch' => array($vendorDir . '/zendframework/zendsearch/library')