Commit 7c3be945 by Phạm Văn Đoan

test tích hợp elasticquent.php

parent 8592bee9
<?php
namespace App\Http\Controllers;
use App\Models\CrawlerListenHistory;
use App\Models\EsListenHistory;
use GuzzleHttp\Client;
class EsController extends Controller
{
public function __construct()
{
ini_set('max_execution_time', -1);
}
public function test()
{
//EsListenHistory::addAllToIndex();
$listen = EsListenHistory::searchByQuery([
'match' => []
]);
return response()->json($listen);
}
public function sync()
{
//$client = new Client(['http://localhost:9200/']);
//$listen = CrawlerListenHistory::take(1000)->skip(0)->get();
//$listen = CrawlerListenHistory::take(1000)->skip(1000)->get();
//$listen = CrawlerListenHistory::take(5000)->skip(0)->get()->toArray();
//$listen = CrawlerListenHistory::take(5000)->skip(5000)->get()->toArray();
//$listen = CrawlerListenHistory::take(10000)->skip(10000)->get()->toArray();
//$listen = CrawlerListenHistory::take(10000)->skip(20000)->get()->toArray();
//$listen = CrawlerListenHistory::take(10000)->skip(30000)->get()->toArray();
$listen = CrawlerListenHistory::take(10000)->skip(40000)->get()->toArray();
foreach ($listen as $val) {
$uri = 'http://localhost:9200/vmusicchart/_doc/' . $val['id'];
$params = [
"id" => intval($val['id']),
"date_log" => $val['date_log'],
"track_id" => intval($val['track_id']),
"alltime_zing" => intval($val['alltime_zing']),
"alltime_nct" => intval($val['alltime_nct']),
"alltime_nhacvn" => intval($val['alltime_nhacvn']),
"alltime_keeng" => intval($val['alltime_keeng']),
"zing_count" => intval($val['zing_count']),
"nct_count" => intval($val['nct_count']),
"nhacvn_count" => intval($val['nhacvn_count']),
"keeng_count" => intval($val['keeng_count']),
"total_listen" => intval($val['total_listen']),
"created_at" => $val['created_at'],
"updated_at" => $val['updated_at']
];
sendRequest($uri, $params, 'PUT', true);
echo "<br>ID = " . $val['id'];
}
/*CrawlerListenHistory::chunk(5000, function ($items){
foreach ($items as $val) {
$uri= 'http://localhost:9200/vmusicchart/_doc/' . $val->id;
$params = [
"id" => intval($val->id),
"date_log" => $val->date_log,
"track_id" => intval($val->track_id),
"alltime_zing" => intval($val->alltime_zing),
"alltime_nct" => intval($val->alltime_nct),
"alltime_nhacvn" => intval($val->alltime_nhacvn),
"alltime_keeng" => intval($val->alltime_keeng),
"zing_count" => intval($val->zing_count),
"nct_count" => intval($val->nct_count),
"nhacvn_count" => intval($val->nhacvn_count),
"keeng_count" => intval($val->keeng_count),
"total_listen" => intval($val->total_listen),
"created_at" => $val->created_at,
"updated_at" => $val->updated_at
];
sendRequest($uri, $params, 'PUT', true);
echo "<br>ID = " . $val->id;
}
});*/
echo 'Xong';
}
}
<?php
namespace App\Models;
use Elasticquent\ElasticquentTrait;
use Illuminate\Database\Eloquent\Model;
class EsListenHistory extends Model
{
use ElasticquentTrait;
protected $table = '_doc';
public $timestamps = true;
protected $fillable = [
'id',
'date_log',
'track_id',
'alltime_zing','alltime_nct','alltime_nhacvn','alltime_keeng',
'zing_count',
'nct_count',
'nhacvn_count',
'keeng_count',
'total_listen'
];
protected $mappingProperties = [
"id" => [
"type" => "integer"
],
"date_log" => [
"type" => "date", "format" => "Y-m-d"
],
"track_id" => [
"type" => "integer"
],
"alltime_zing" => [
"type" => "integer"
],
"alltime_nct" => [
"type" => "integer"
],
"alltime_nhacvn" => [
"type" => "integer"
],
"alltime_keeng" => [
"type" => "integer"
],
"zing_count" => [
"type" => "integer"
],
"nct_count" => [
"type" => "integer"
],
"nhacvn_count" => [
"type" => "integer"
],
"keeng_count" => [
"type" => "integer"
],
"total_listen" => [
"type" => "integer"
],
"created_at" => [
"type" => "date", "format" => "Y-m-d H:i:s"
],
"updated_at" => [
"type" => "date", "format" => "Y-m-d H:i:s"
]
];
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"require": { "require": {
"php": ">=5.6.4", "php": ">=5.6.4",
"elasticquent/elasticquent": "^1.0", "elasticquent/elasticquent": "^1.0",
"guzzlehttp/guzzle": "6",
"ixudra/curl": "^6.19", "ixudra/curl": "^6.19",
"laravel/framework": "5.4.*", "laravel/framework": "5.4.*",
"laravel/tinker": "~1.0", "laravel/tinker": "~1.0",
......
...@@ -170,6 +170,7 @@ return [ ...@@ -170,6 +170,7 @@ return [
Yangqi\Htmldom\HtmldomServiceProvider::class, Yangqi\Htmldom\HtmldomServiceProvider::class,
Maatwebsite\Excel\ExcelServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class,
Elasticquent\ElasticquentServiceProvider::class, Elasticquent\ElasticquentServiceProvider::class,
Ixudra\Curl\CurlServiceProvider::class,
/* /*
* Application Service Providers... * Application Service Providers...
...@@ -231,6 +232,7 @@ return [ ...@@ -231,6 +232,7 @@ return [
'Htmldom' => Yangqi\Htmldom\Htmldom::class, 'Htmldom' => Yangqi\Htmldom\Htmldom::class,
'Excel' => Maatwebsite\Excel\Facades\Excel::class, 'Excel' => Maatwebsite\Excel\Facades\Excel::class,
'Es' => Elasticquent\ElasticquentElasticsearchFacade::class, 'Es' => Elasticquent\ElasticquentElasticsearchFacade::class,
'Curl' => Ixudra\Curl\Facades\Curl::class,
], ],
......
...@@ -27,6 +27,6 @@ return array( ...@@ -27,6 +27,6 @@ return array(
| Elasticquent models. | Elasticquent models.
*/ */
'default_index' => 'vmuscichart', 'default_index' => 'vmusicchart',
); );
...@@ -14,3 +14,7 @@ ...@@ -14,3 +14,7 @@
Route::get('/', function () { Route::get('/', function () {
return view('welcome'); return view('welcome');
}); });
Route::get('/elasticsearch', 'EsController@test');
Route::get('/elasticsearch-sync', 'EsController@sync');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment