Hi,
I was trying to use Solarium PHP Solr client with Codeigniter 4 but having issues. I used composer to download all dependencies at my desktop & then copied whole folder in app/ThirdParty.
Then added following line in config/Autoload:
PHP Code:
'Solarium' => APPPATH . 'ThirdParty/Solarium/vendor/autoload.php' ,
Then I created app/Config/Solarium_config.php and added following:
PHP Code:
<?php namespace Config ; use CodeIgniter \ Config \ BaseConfig ; class Solarium_config extends BaseConfig { public $config = array( 'endpoint' => array( 'localhost' => array( 'host' => '127.0.0.1' , 'port' => 8983 , 'path' => '/solr/' , 'core' => 'db' , // For Solr Cloud you need to provide a collection instead of core: // 'collection' => 'techproducts', ) ) ); }
Then I added following in Home Controller:
PHP Code:
<?php namespace App \ Controllers ; use Config \ App ; use App \ ThirdParty \ Solarium ; class Home extends BaseController { protected $config ; public function __construct () { $this -> solr_con = config ( 'Solarium_config' ); } public function index () { // create a client instance $client = new Client ( $adapter , $eventDispatcher , $this -> solr_con ); // get a select query instance $query = $client -> createSelect (); // get the facetset component $facetSet = $query -> getFacetSet (); // create a facet field instance and set options $facetSet -> createFacetField ( 'stock' )-> setField ( 'inStock' ); // this executes the query and returns the result $resultset = $client -> select ( $query ); // display the total number of documents found by solr echo 'NumFound: ' . $resultset -> getNumFound (); // display facet counts echo '<hr/>Facet counts for field "inStock":<br/>' ; $facet = $resultset -> getFacetSet ()-> getFacet ( 'stock' ); foreach ( $facet as $value => $count ) { echo $value . ' [' . $count . ']<br/>' ; } // show documents using the resultset iterator foreach ( $resultset as $document ) { echo '<hr/><table>' ; echo '<tr><th>id</th><td>' . $document -> id . '</td></tr>' ; echo '<tr><th>name</th><td>' . $document -> name . '</td></tr>' ; echo '<tr><th>price</th><td>' . $document -> price . '</td></tr>' ; echo '</table>' ; } } //-------------------------------------------------------------------- //-------------------------------------------------------------------- }
But what i get following error message, which means I am making mistakes, kindly help
Code:
ERROR Class 'App\Controllers\Client' not found
Note: I have attached all files and solarium folder for your review.
Regards
Attached Files
Attachments.zip (Size: 494.65 KB / Downloads: 6)