PHP code example of pdphilip / opensearch
1. Go to this page and download the library: Download pdphilip/opensearch 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/ */
pdphilip / opensearch example snippets
UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
UserLog::create([
'user_id' => '2936adb0-b10d-11ed-8e03-0b234bda3e12',
'ip' => '62.182.98.146',
'location' => [40.7185,-74.0025],
'country_code' => 'US',
'status' => 1,
]);
UserLog::where('status', 1)->update(['status' => 4]);
UserLog::where('status', 4)->orderByDesc('created_at')->paginate(50);
UserProfile::whereIn('country_code',['US','CA'])
->orderByDesc('last_login')->take(10)->get();
UserProfile::where('state','unsubscribed')
->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
UserProfile::searchTerm('Laravel')->orSearchTerm('opensearch')->get();
UserProfile::searchPhrasePrefix('loves espressos and t')->highlight()->get();
UserProfile::whereMatch('bio', 'PHP')->get();
UserLog::whereGeoDistance('location', '10km', [40.7185,-74.0025])->get();
UserProfile::whereFuzzy('description', 'qick brwn fx')->get();
UserLog::where('status', 1)->orderByDesc('created_at')->with('user')->get();
'opensearch' => [
'driver' => 'opensearch',
'hosts' => explode(',', env('OS_HOSTS', 'http://localhost:9200')),
'basic_auth' => [
'username' => env('OS_USERNAME', ''),
'password' => env('OS_PASSWORD', ''),
],
'sig_v4' => [
'provider' => env('OS_SIG_V4_PROVIDER'),
'region' => env('OS_SIG_V4_REGION'),
'service' => env('OS_SIG_V4_SERVICE'),
],
'ssl' => [
'cert' => env('OS_SSL_CERT', ''),
'cert_password' => env('OS_SSL_CERT_PASSWORD', ''),
'key' => env('OS_SSL_KEY', ''),
'key_password' => env('OS_SSL_KEY_PASSWORD', ''),
],
'index_prefix' => env('OS_INDEX_PREFIX', false),
'options' => [
'bypass_map_validation' => env('OS_OPT_BYPASS_MAP_VALIDATION', false),
'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
'retires' => env('OS_OPT_RETRIES',null),
'sniff_on_start' => env('OS_OPT_SNIFF_ON_START',false),
'logging' => env('OS_OPT_LOGGING', false),
'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS',false),
'default_limit' => env('OS_OPT_DEFAULT_LIMIT', 1000),
'allow_id_sort' => env('OS_OPT_ID_SORTABLE', false),
],
],
//config/app.php
'providers' => [
...
...
PDPhilip\OpenSearch\OpenSearchServiceProvider::class,
...
//bootstrap/providers.php
return [
App\Providers\AppServiceProvider::class,
PDPhilip\OpenSearch\OpenSearchServiceProvider::class,
];