1. Go to this page and download the library: Download codemix/yiielasticsearch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class MyModel extends CActiveRecord
{
public function behaviors()
{
return array(
'searchable' => array(
'class' => 'YiiElasticSearch\SearchableBehavior',
),
);
}
}
class MyModel extends CActiveRecord
{
public $elasticIndex = 'myindex';
class MyModel extends CActiveRecord
{
public function getElasticIndex()
{
return 'myindex';
}
class MyModel extends CActiveRecord
{
public $elasticType = 'mymodel';
class MyModel extends CActiveRecord
{
public function getElasticType()
{
return 'mymodel';
}
class MyModel extends CActiveRecord
{
/**
* @param DocumentInterface $document the document where the indexable data must be applied to.
*/
public function populateElasticDocument(DocumentInterface $document)
{
$document->setId($this->id);
$document->name = $this->name;
$document->street = $this->street;
}
/**
* @param DocumentInterface $document the document that is providing the data for this record.
*/
public function parseElasticDocument(DocumentInterface $document)
{
// You should always set the match score from the result document
if ($document instanceof SearchResult)
$this->setElasticScore($document->getScore());
$this->id = $document->getId();
$this->name = $document->name;
$this->street = $document->stree;
}
$search = new \YiiElasticSearch\Search("myindex", "mymodel");
$search->query = array(
"match_all" => array()
);
// start returning results from the 20th onwards
$search->offset = 20;