1. Go to this page and download the library: Download skvn/plastic 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/ */
skvn / plastic example snippets
Sleimanx2\Plastic\PlasticServiceProvider::class
use Sleimanx2\Plastic\Searchable;
class Book extends Model
{
use Searchable;
}
public $searchable = ['id', 'name', 'body', 'tags', 'images'];
public function buildDocument()
{
return [
'id' => $this->id,
'tags' => $this->tags
];
}
$result = Book::search()->match('title','pulp')->get();
// Returns a collection of Book Models
$books = $result->hits();
// Returns the total number of matched documents
$result->totalHits();
// Returns the highest query score
$result->maxScore();
//Returns the time needed to execute the query
$result->took();
//this be handy if you have a custom index for your model
Tag::suggest()->term('tag_term','admin')->get();
use Sleimanx2\Plastic\Map\Blueprint;
use Sleimanx2\Plastic\Mappings\Mapping;
class AppTag extends Mapping
{
/**
* Full name of the model that should be mapped
*
* @var string
*/
protected $model = App\Tag::class;
/**
* Run the mapping.
*
* @return void
*/
public function map()
{
Map::create($this->getModelType(), function (Blueprint $map) {
$map->string('name')->store('true')->index('analyzed');
// instead of the fluent syntax we can use the second method argument to fill the attributes
$map->completion('suggestion', ['analyzer' => 'simple', 'search_analyzer' => 'simple']);
},$this->getModelIndex());
}
}