PHP code example of best-served-cold / laravel-zendsearch
1. Go to this page and download the library: Download best-served-cold/laravel-zendsearch 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/ */
best-served-cold / laravel-zendsearch example snippets
// ...
use BestServedCold\LaravelZendSearch\Laravel\SearchTrait;
class User extends Model
{
use SearchTrait;
// ...
// ...
public static function searchFields()
{
self::setSearchFields(['some', 'fields']);
}
// ...
// ...
public static function boostFields()
{
self::setBoostFields(['some' => 0.8, 'fields' => 1.0]);
}
// ...
$search = UserModel::search();
// add your query
$search->where('string', 'field');
// add an exact match
$search->match('string', 'field');
// Search all fields
$search->where('string');
// limit your query
$search->limit(10);
// get your hits (primary keys in an array)
$ids = $search->hits();
// and or, get your eloquent collection
$result = $search->get();
// Or chain it:
$result = User::search()->where('term', 'field')->limit(15)->offset(10)->get();
// Make sure you've got a collection like so
User::search()->where('term', 'field')->first()->delete();
$search = UserModel::search();
// Wildcard
$search->wildcard('ter*', 'field');
// Phrase
$search->phrase('this is the phrase', 'field', [1, 2, 3, 4]);
// Fuzzy
$search->fuzzy('term', 'field');
// Term
$search->term('complete_term', 'field');
// Get the last query
BestServedCold\LaravelZendSearch\Lucene\Search::getLastQuery()->__toString();
BestServedCold\LaravelZendSearch\Lucene\Filter::setAnalyzer(
new ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num\CaseInsensitive;
);
BestServedCold\LaravelZendSearch\Lucene\Filter::addFilter(
new ZendSearch\Lucene\Analysis\TokenFilter\LowerCaseUtf8;
);
// Returns the last ZendSearch\Lucene\Document inserted.
var_dump(BestServedCold\LaravelZendSearch\Lucene\Store::getLastInsert());
// Returns the current set of filters or analyzer
var_dump(BestServedCold\LaravelZendSearch\Lucene::getFilters());
var_dump(BestServedCold\LaravelZendSearch\Lucene::getAnalyzer());
// Returns the last ZendSearch\Lucene\Search\Query\Boolean object to interrogate.
var_dump(BestServedCold\LaravelZendSearch\Lucene::getLastQuery()->__toString());
bash
php artisan vendor:publish
shell
php artisan search:rebuild --verbose
shell
php artisan search:destroy --verbose
shell
php artisan search:optmise --verbose
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.