PHP code example of honvid / laravel-search
1. Go to this page and download the library: Download honvid/laravel-search 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/ */
honvid / laravel-search example snippets
'providers' => array(
// ...
'Honvid\Providers\SearchServiceProvider',
)
'aliases' => array(
// ...
'Search' => 'Honvid\Facades\Search',
)
Search::insert(1, array(
'title' => 'My title',
'content' => 'The quick brown fox...',
'status' => 'published',
));
Search::insert(
"post-1",
array(
'title' => 'My title',
'content' => 'The quick brown fox...',
'status' => 'published',
),
array(
'created_at' => time(),
'creator_id' => 5,
)
);
Search::delete(1);
Search::deleteIndex();
$results = Search::search('content', 'fox')->get();
$results = Search::search(array('title', 'content'), 'fox')->get();
$results = Search::search(null, 'fox')->get();
$results = Search::search('content', 'update', array('fuzzy'=>true))->get();
$results = Search::search('content', 'fox')
->where('status', 'published')
->get();
$results = Search::search('content', 'fox')
->whereLocation(36.16781, -96.023561, 10000)
->get();
$results = Search::search('content', 'fox')
->where('status', 'published')
->limit(10) // Limit 10
->get();
$results = Search::search('content', 'fox')
->where('status', 'published')
->limit(10, 30) // Limit 10, offset 30
->get();
$paginator = Search::search('content', 'fox')->paginate(15);
$results = Search::select('id', 'created_at')
->search('content', 'fox')
->get();
$results = Search::select('id', 'created_at')
->where('title', 'My title')
->where('status', 'published')
->search('content', 'fox')
->search('content', 'quick')
->limit(10)
->get();
Search::search('content', 'fox')->delete();
Search::index('posts')->insert(1, array(
'title' => 'My title',
'content' => 'The quick brown fox...',
'status' => 'published',
));
$results = Search::index('posts')->search('content', 'fox')
->where('status', 'published')
->get();
Search::index('posts')->delete(1);
Search::index('posts')->deleteIndex();
$results = Search::index('posts')->select('id', 'created_at')
->search('content', 'fox')
->addCallback(function ($query) {
// Make changes to $query...
return $query;
})
->get();
$results = Search::index('posts')->select('id', 'created_at')
->search('content', 'fox')
->addCallback(function ($query) {
// Adjust pagination for an elasticsearch query array.
$query['from'] = 0;
$query['size'] = 20;
return $query;
}, 'elasticsearch')
->get();
console
$ php artisan vendor:publish --provider="Honvid\Providers\SearchServiceProvider"