1. Go to this page and download the library: Download winter/wn-search-plugin 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/ */
winter / wn-search-plugin example snippets
namespace Winter\Plugin\Models;
use Model;
class MyModel extends Model
{
public $implement = [
\Winter\Search\Behaviors\Searchable::class,
];
}
namespace Winter\Plugin\Models;
use Model;
class Post extends Model
{
public $implement = [
\Winter\Search\Behaviors\Searchable::class,
];
public $searchable = [
'title',
'summary'
];
}
namespace Winter\Plugin\Models;
use Model;
class Post extends Model
{
public $implement = [
\Winter\Search\Behaviors\Searchable::class,
];
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();
// Customize the data array...
return $array;
}
}
namespace Winter\Plugin;
class Plugin extends \System\Classes\PluginBase
{
public function boot()
{
\ThirdParty\Plugin\Models\Model::extend(function ($model) {
$model->implement[] = \Winter\Search\Behaviors\Searchable::class;
// Add a dynamic property to specify the searchable data
$model->addDynamicProperty('searchable', [
'id',
'title',
'description',
]);
// Or, add a dynamic method instead.
$model->addDynamicMethod('toSearchableArray', function () use ($model) {
$array = $model->toArray();
// Customize the data array...
return $array;
});
});
}
}
namespace Winter\Plugin\Models;
use Model;
class User extends Model
{
public $implement = [
\Winter\Search\Behaviors\Searchable::class,
];
/**
* Get the value used to index the model.
*
* @return mixed
*/
public function getSearchKey()
{
return $this->email;
}
/**
* Get the key name used to index the model.
*
* @return mixed
*/
public function getSearchKeyName()
{
return 'email';
}
}
$results = \Acme\Blog\BlogSearch::doSearch('install winter cms')->getWithRelevance(function ($model, array $words) {
// Score each record and return score as a integer or float.
});